pub fn float_to_decimal_opt<D>(
input: f64,
precision: u8,
scale: i8,
) -> Option<D::Native>where
D: DecimalType,
D::Native: DecimalCast,Expand description
Like float_to_decimal, but returns None on failure.
With valid precision and scale, conversion failures do not allocate an error message.
use arrow_array::types::Decimal32Type;
use arrow_cast::cast::float_to_decimal_opt;
assert_eq!(float_to_decimal_opt::<Decimal32Type>(12.345, 5, 2), Some(1235));
assert_eq!(float_to_decimal_opt::<Decimal32Type>(12345.678, 5, 2), None);