Code Monkey home page Code Monkey logo

d-money's Introduction

Build Status Coverage 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"

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.

DDoc documentation on Github pages.

Licence is Boost v1.0.

d-money's People

Contributors

qznc avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.