Arbitrary-precision decimal numbers for Dart
open sourceApache-2.0free
decimal is a Dart package for doing arithmetic on decimal numbers without the rounding errors of doubles: 0.2 + 0.1 gives 0.3, not 0.30000000000000004. Values are parsed from strings with Decimal.parse, and a companion library formats them with the intl package's number formats through DecimalFormatter. It works in Dart and Flutter apps.
Problems it solves
- add money amounts in Dart without floating-point errors
- 0.1 + 0.2 isn't 0.3 in my Flutter app
- store and format exact decimal prices in Dart
Features
- exact decimal arithmetic without floating-point rounding
- Decimal.parse from strings
- formatting with intl number formats via DecimalFormatter
- works in Dart and Flutter
Limitations
- Formatting with intl doesn't work with maximumFractionDigits above 15 on the web or 18 on other platforms (README, 30 May 2024).1
