logoalt Hacker News

rednb • yesterday at 7:22 PM • 3 replies • view on HN

Wow, what a vicious footgun. I do a lot of work related to pricing, invoicing, exchange rates etc... where decimals do matter, so this kind of stresses me out. Thanks for the heads up.


Replies

bazoom42 • yesterday at 7:41 PM

You shouldn’t cast from double to decimal anyway. Just use decimal throughout.

➕ show 3 replies
kevin_thibedeau • today at 12:32 AM

0.1 is not representable in binary floating point. The old behavior was adding magic that shouldn't be there.

➕ show 1 reply
ExoticPearTree • today at 8:49 AM

> Wow, what a vicious footgun.

We do too at $dayjob, but use cents for everything and at the end of the calculation we divide by 100 to get the dollar amount.

Exchange rates are 4 decimals, so you would still not get bit by this.