Decimal.fromFraction constructor

Decimal.fromFraction(
  1. BigInt numerator,
  2. BigInt denominator, {
  3. required int scale,
  4. DecimalRounding rounding = DecimalRounding.exact,
})

Converts an integer fraction to a finite decimal at an explicit scale. Only the rounded result must fit the finite Decimal range.

Implementation

factory Decimal.fromFraction(
  BigInt numerator,
  BigInt denominator, {
  required int scale,
  DecimalRounding rounding = DecimalRounding.exact,
}) {
  validateScale(scale);
  if (denominator == BigInt.zero) throw UnsupportedError('Division by zero');
  return _quotient(
    numerator * (scale > 0 ? _power(scale) : BigInt.one),
    denominator * (scale < 0 ? _power(-scale) : BigInt.one),
    scale,
    rounding,
  );
}