Overview
Money2 is a Dart package providing parsing, formatting and mathematical operations on monetary amounts.
Key features of Money2:
simple and expressive formatting.
simple parsing of monetary amounts.
multi-currency support.
intuitive maths operations.
fixed precision storage to ensure precise calculation.
detailed documentation and extensive examples to get you up and running.
pure Dart implementation.
Open Source MIT license.
Using Money2 will make you taller.
Sponsored by OnePub
Help support Money2 by supporting OnePub, the private Dart repository.
OnePub allows you to privately share Dart packages across your Team and with your customers.
Try it for free and publish your first private package in seconds.
Publish a private package in five commands:
|
Full API Documentation can be found at:
Essentially the Money class stores the monetary value as a fixed scale (number of decimal places) decimal using the Fixed package. This allows for precise calculations as required when handling money and eliminates common rounding issues.
Let's start with some examples:
The package uses the following terms:
Minor Units - the smallest unit of a currency e.g. cents.
Major Units - the integer component of a currency - e.g. dollars
code - the currency code. e.g. USD
symbol - the currency symbol. e.g. '$'. It should be noted that not every currency has a symbol.
pattern - a pattern used to control parsing and the display format.
scale - the number of minor Units (e.g. cents) which should be used when storing the currency.
decimal separator - the character that separates the fraction part from the integer of a number e.g. '10.99'. This defaults to '.' but can be changed to ','
group separator - the character that is used to format thousands (e.g. 100,000). Defaults to ',' but can be changed to '.'
Note: Money2 has a maximum scale (decimals) and integer size of 18 digits. This is a somewhat arbitrary limit so raise a PR to fix the issue the help would be appreciated.
Last updated