On Monday, 6 June 2016 at 20:19:20 UTC, Observer wrote:
On Monday, 6 June 2016 at 19:55:53 UTC, DLearner wrote:
If we allow _int foo;_ to declare an integer variable foo, then suggest we have _dec bar(a,b);_ to declare a decimal variable bar with a units in total length, b units of decimal places. D language then defines how (for example) assignment is carried out (by default), and also provides mechanisms for alternatives (ie some sort of dec_trunc() and dec_round() functions).

And when real-world money is involved, you'd better have arithmetic
overflow trigger an exception, not just wrap around silently.

I made an abstraction, which uses long internally. If the value range is big enough, it works fine.

http://code.dlang.org/packages/money

Reply via email to