Suggested enhancement: New basic datatype: 'dec'.

Adrian Matoga via Digitalmars-d digitalmars-d at puremagic.com
Thu Jun 25 02:36:18 PDT 2015


On Thursday, 25 June 2015 at 09:24:28 UTC, DLearner wrote:
> A signed decimal datatype to support writing userland 
> accounting programs (major business application area), without 
> loss of accuracy (including losses caused by not all 'decimal 
> decimals' having exact 'binary decimal' representation).
>
> Syntax:
>
> dec(a,b) foo;
>
> Where a is an integer 1<=a<=99 (total no of digits, including 
> any decimal digits).
> b is also an integer 0 <= b <= a (no. of decimal digits);
>
> b = 0 implies b can be omitted e.g. 'dec(4,0) foo;' can also be 
> written 'dec(4) foo;'.
>
> Basic arithmetic supported.
> Normal assignment rule is truncation/padding, but a 'round(d)' 
> function to round to d decimal places provided.
> Also provide a formatting function to convert dec type to 
> printable character string.
>
> Not very interesting from a theoretical viewpoint (just COBOL 
> or PL/I datatype),
> but (I think) of practical value in encouraging D adoption.

Decimal data type is something that can and should be done in 
library, not in the language itself. There is already a proposed 
implementation, you too can review it:
http://wiki.dlang.org/Review_Queue
https://github.com/andersonpd/eris/tree/master/decimal


More information about the Digitalmars-d mailing list