decimal
3.2.6, released 4 months ago by an unverified publisher
Arbitrary-precision decimal arithmetic for Dart
What it does
Provides a Decimal type that avoids floating‑point precision loss. It supports arithmetic, comparison, and formatting via intl.
AI-written summary of version 3.2.6, based on the package's README and metadata. Report an inaccuracy
Use it when
- Need exact decimal math (e.g., finance, scientific calculations)
- Want to format decimals with intl NumberFormat
- Require consistent results across platforms
Skip it when
- Only need simple double math
- Performance critical and can tolerate floating‑point errors
Strengths
- Precise decimal arithmetic
- Built‑in formatting helpers
- Works on all Dart platforms
Weaknesses
- Adds a dependency on intl for formatting
- No built‑in JSON serialization
- Not a code‑generation library
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 2
Add dependency in pubspec and import 'package:decimal/decimal.dart';
import 'package:decimal/decimal.dart';
void main() {
var a = Decimal.parse('0.2');
var b = Decimal.parse('0.1');
print(a + b); // 0.3
}
Alternatives
Packages that do the same job and could replace decimal.
- async_task
Parallel task executor using isolates or async, like thread pools
78Compare - result_monad
Dart Result Monad for handling success/failure without exceptions
64Compare - text
Get detailed text metrics like lines, character positions, and locations.
51Compare - number_to_word_arabic
Convert integer numbers to Arabic words up to 99 trillion.
47Compare
Works with
Packages commonly used together with decimal: ones it builds on, ones built on it, and its own family.
- intldecimal depends on itA Dart library for internationalization and localization, providing message translation, plural/gender handling, and date/number formatting.
- rationaldecimal depends on itAllows you to deal with rational numbers in Dart.
- json_schema_builderBuilt on decimalBuild and validate JSON Schemas in Dart with a fluent, type‑safe API
- fixedBuilt on decimalFixed decimal numbers with a fixed scale, stored as BigInts, supporting math, formatting and parsing.
- money2Built on decimalHigh-precision library for storing, parsing, formatting, and performing arithmetic on money.
- bsonBuilt on decimalBSON binary-encoded serialization library for Dart and EJSON support.
- mongo_dartBuilt on decimalMongoDB driver implemented in pure Dart for server-side applications.
- proto_annotationsBuilt on decimalAnnotations to mark and configure business model classes for code generation of .proto and Dart mappers.