decimal type in d
IGotD-
nise at nise.com
Mon May 16 09:46:57 UTC 2022
On Sunday, 15 May 2022 at 13:26:30 UTC, vit wrote:
> Hello, I want read decimal type from sql db, do some arithmetic
> operations inside D program and write it back to DB. Result
> need to be close to result as if this operations was performed
> in sql DB. Something like C# decimal.
> Exists this kind of library ind D? (ideally `pure @safe @nogc
> nothrow`).
This also something I wondered, it should be standard in the D
library. Implementing it can be done straight forward with
existing D language primitives, essentially a struct.
For those who don't know, decimal in C# is like a floating point
value but the exponent is a power of 10 (internally total 16
bytes). This means that for "simple" mathematics rational decimal
values remains rational decimals values and not some rounded
value that would happen if you would use normal floating point
values. The decimal type is essential for financial calculations.
I think D can more or less copy the C# solution.
More information about the Digitalmars-d-learn
mailing list