fixed
6.3.0, released 4 weeks ago by onepub.dev
Fixed decimal numbers with a fixed scale, stored as BigInts, supporting math, formatting and parsing.
What it does
Provides a Fixed type that stores decimal numbers with a selectable number of decimal places using BigInts for precision. It offers arithmetic operators, comparison, formatting (including locale-aware) and parsing with error handling.
AI-written summary of version 6.3.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- Need precise decimal arithmetic for currencies or financial data
- Require locale-aware formatting and parsing of decimal numbers
- Want to avoid floating-point inaccuracies in calculations
Skip it when
- Working with arbitrary-precision decimals beyond a fixed scale
- Needing binary floating-point math for performance-critical code
Strengths
- High precision via BigInt storage
- Built-in formatting and parsing with locale support
- Full set of arithmetic operators and comparison
- Consistent hash codes across different scales
Weaknesses
- Limited to a fixed number of decimal places
- No support for arbitrary-precision beyond the set scale
- Requires Dart SDK 3.9.0 or higher
Setup
- Kind
- Pure Dart
- Effort
- Low
- Code generation
- No
- Direct dependencies
- 3
import 'package:fixed/fixed.dart';
void main() {
final t1 = Fixed.fromNum(1, decimalDigits: 2); // 1.00
final t2 = Fixed.fromNum(1, decimalDigits: 3); // 1.000
final add = t1 + Fixed.ten;
final multiply = t1 * t2;
print(add); // 11.00
print(multiply); // 1.00000
}
Alternatives
Packages that do the same job and could replace fixed.
- math_expressions
Parse and evaluate mathematical expressions in real, vector, and interval contexts.
79Compare - deep_pick
Type-safe API for manual JSON parsing with useful error messages.
91Compare - phone_numbers_parser
Dart library for parsing, validating, and formatting international phone numbers.
87Compare - dlibphonenumber
Parse, format, validate and extract international phone numbers in pure Dart.
77Compare
Works with
Packages commonly used together with fixed: ones it builds on, ones built on it, and its own family.
- intlfixed depends on itA Dart library for internationalization and localization, providing message translation, plural/gender handling, and date/number formatting.
- decimalfixed depends on itArbitrary-precision decimal arithmetic for Dart
- money2Built on fixedHigh-precision library for storing, parsing, formatting, and performing arithmetic on money.