Decimal.fromDoubleWithRoundTripPrecision constructor

Decimal.fromDoubleWithRoundTripPrecision(
  1. double f
)

Construct an Decimal from an float, with enough digits to recover the original floating point in IEEE 754 without needing trailing zeros

See the Rust documentation for try_from_f64 for more information.

See the Rust documentation for FloatPrecision for more information.

Throws DecimalLimitError on failure.

Implementation

factory Decimal.fromDoubleWithRoundTripPrecision(double f) {
  final result = _icu4x_Decimal_from_double_with_round_trip_precision_mv1(f);
  if (!result.isOk) {
    throw DecimalLimitError();
  }
  return Decimal._fromFfi(result.union.ok, []);
}