Is using floating point type for money/currency a good idea?

rikki cattermole rikki at cattermole.co.nz
Mon May 20 22:19:45 UTC 2019


On 20/05/2019 11:10 PM, Boqsc wrote:
> https://dlang.org/spec/float.html
> 
> I'm frozen in learning basics of D lang since I want to create a simple 
> game and I really would like a clean and simple code, however to me 
> floating points are magic.
> 
> https://wiki.dlang.org/Review_Queue
> Since std.decimal is still work in progress and apparently its 
> development is stuck for a while, should I just somehow use floating 
> point to store currency or wait until Decimal package will be finally 
> included into std Phobos of D lang?

While other posters have explained the best practice for currency in the 
real world, for games even AAA uses floats. Don't fret it, it doesn't 
matter. You won't loose actual money if its off by a few cents here or 
there.


More information about the Digitalmars-d-learn mailing list