Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
August 09, 2016 Decimal/Currency Type | ||||
---|---|---|---|---|
| ||||
There has been a question or two about this before, but I really don't feel there has been a reasonable answer (or I have missed it). I am wondering if there is a fixed decimal type, either built-in or implemented in Phobos (similar to python's "Decimal" or Java's "BigDecimal"). Previous posts suggested using a long and keeping track of the decimal point, but there are a few problems with that. First, arithmatic with, or assignments from, other types wouldn't translate properly (the built in types have no awareness of the decimal point location associated with the long). Second, if using for currency as an example, I could probably get by with long if only tracking cents, but what if I wanted to track thousandths of a cent or more? That wouldn't leave me with much place values to track large dollar amounts. Is there such a thing build into D? If not, is there any plans to add it? It seems like this would be something needed by many applications (especially anything dealing with currency). |
August 09, 2016 Re: Decimal/Currency Type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zane | On Tuesday, 9 August 2016 at 10:48:50 UTC, Zane wrote: > Is there such a thing build into D? If not, is there any plans to add it? It seems like this would be something needed by many applications (especially anything dealing with currency). I don't think there is anything in the standard library, but there is a dub library: https://github.com/qznc/d-money |
August 09, 2016 Re: Decimal/Currency Type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zane | On Tuesday, 9 August 2016 at 10:48:50 UTC, Zane wrote: > > Is there such a thing build into D? If not, is there any plans to add it? It seems like this would be something needed by many applications (especially anything dealing with currency). Hi, the lack of a decimal type in Phobos is known and it is added to the vision list [1]. In addition to the dub package there is one in the review queue [2]. Also it seems there is a C package from IBM?, which could might be included into phobos via a binding. [1] https://wiki.dlang.org/Vision/2016H2 [2] https://wiki.dlang.org/Review_Queue Kind regards André |
August 09, 2016 Re: Decimal/Currency Type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Edwin van Leeuwen | On Tuesday, 9 August 2016 at 11:14:09 UTC, Edwin van Leeuwen wrote:
> On Tuesday, 9 August 2016 at 10:48:50 UTC, Zane wrote:
>> Is there such a thing build into D? If not, is there any plans to add it? It seems like this would be something needed by many applications (especially anything dealing with currency).
>
> I don't think there is anything in the standard library, but there is a dub library:
> https://github.com/qznc/d-money
This is the "get by with long, but" approach. The downside is the limited range. The upside is (probably) speed.
|
August 09, 2016 Re: Decimal/Currency Type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andre Pany | Thanks to all who replied (especially Andre). I am glad to hear that it is part of the plan to include this eventually (it's also nice to read some of the other plans I was not familiar with). I don't use D for very serious projects yet, but have been following it for years for its long-term potential. I just wanted to make sure fixed-point decimal was being considered for the standard instead of being swept under the rug because of the previous "long" suggestions. Thanks again! |
August 10, 2016 Re: Decimal/Currency Type | ||||
---|---|---|---|---|
| ||||
Posted in reply to Zane | On Tuesday, 9 August 2016 at 10:48:50 UTC, Zane wrote: > There has been a question or two about this before, but I really don't feel there has been a reasonable answer (or I have missed it). > > [...] There is one in the review queue since forever. https://wiki.dlang.org/Review_Queue Maybe take a look at that? |
Copyright © 1999-2021 by the D Language Foundation