money 3.0.2

A money data type, for easy and safe handling of currency amounts


To use this package, run the following command in your project's root directory:

Manual usage
Put the following dependency into your project's dependences section:

Build Status Travis Build status Appveyor codecov status Dub Package

D-Money

Handling amounts of money safely and efficiently.

Floating point is imprecise. Integer is fragile. BigNum and similar are slow. All lack type safety, like forbidding addition different currencies.

Features:

  • support different rounding modes
  • can not mix currencies (e.g. EUR vs USD)
  • efficient integer arithmetic
  • overflow checking for arithmetic
  • type checking for currencies, precision, and rounding mode
  • yet generic equality and comparison
    alias EUR = currency!("EUR");

    assert(EUR(100.0001) == EUR(100.00009));
    assert(EUR(3.10) + EUR(1.40) == EUR(4.50));
    assert(EUR(3.10) - EUR(1.40) == EUR(1.70));
    assert(EUR(10.01) * 1.1 == EUR(11.011));

    writefln("%d", EUR(3.6)); // "4EUR"
    writefln("%f", EUR(3.141592)); // "3.1416EUR"
    writefln("%.2f", EUR(3.145)); // "3.15EUR"
    writefln("%.2f", EUR("3.145")); // "3.15EUR"

Scope is smaller than JSR 354, for example, which also considers conversion and meta data. A conversion rate depends on target date and time, the currencies involved, the provider, the amount, and other factors. If you need meta data, then wrap currency into your own data type.

Available via dub on code.dlang.org.

Licence is Boost v1.0.

Authors:
Dependencies:
none
Versions:
3.0.2 2021-Jun-10
3.0.1 2020-Jun-08
3.0.0 2020-Jun-06
2.5.0 2020-May-29
2.4.0 2020-May-28
Show all 14 versions
Download Stats:
  • 23 downloads today

  • 87 downloads this week

  • 403 downloads this month

  • 57543 downloads total

Score:
3.9
Short URL:
money.dub.pm