extensions/numeric_extensions library

Provides extension methods for numeric types including rounding, formatting, parsing, and validation operations.

This library extends Dart's numeric types (int, double, BigInt, Rational) with practical utilities for financial calculations, measurements, and general numeric operations requiring precision.

Key features:

  • Multiple rounding modes (floor, ceil, truncate, up, halfUp, halfDown, halfEven)
  • Localized formatting for currency and percentages
  • Rational parsing with support for fractions and mixed numbers
  • Range checking and tolerance-based comparisons
  • Percentage calculations

Classes

RationalParsing
A utility class for parsing strings into Rational objects with round-trip support. Unlike Rational.parse, which only handles integers, decimals, and scientific notation, this class can parse fractions (e.g., "7/4") produced by Rational.toString, ensuring compatibility with its output format as well as mixed fractions (e.g., "1 3/4").

Enums

RoundingMode
Defines standard rounding modes for numerical rounding

Extensions

BigIntIsInRangeExtension on BigInt
Extension on BigInt to support isInRange
BigIntMultipleOfExtension on BigInt
Extension on BigInt to support isMultipleOf, isInRange
BigIntRoundedDivisionExtension on BigInt
Extension on BigInt to support division with rounding
BigIntToleranceExtension on BigInt
Extension on BigInt to support isWithinTolerance
DoubleIsInRangeExtension on double
Extension on double to support isInRange
DoubleMultipleOfExtension on double
Extension on double to support isMultipleOf
DoubleToleranceExtension on double
Extension on double to support isWithinTolerance and isCloseTo
IntIsInRangeExtension on int
Extension on int to support isInRange
IntMultipleOfExtension on int
Extension on int to support isMultipleOf
IntToleranceExtension on int
Extension on int to support isWithinTolerance
RationalCommonRoundingExtension on Rational
An extension on Rational to provide some common rounding functionality
RationalFormattingExtension on Rational
An extension on Rational to provide additional formatting functionality
RationalIsInRangeExtension on Rational
Extension on Rational to support isInRange
RationalMultipleOfExtension on Rational
Extension on Rational to support isMultipleOf
RationalPercentageExtension on Rational
Extension on Rational to provide percentage calculation utilities
RationalRoundingExtension on Rational
An extension on Rational to provide rounding functionality
RationalToleranceExtension on Rational
Extension on Rational to support isWithinTolerance and isCloseTo