News for hackers. Stuff that matters.
Re:Why does 0.1 and 0.2 = 0.30000000000000004? by wyager on Wednesday February 08, 2023 @02:14PM (#34713228)
Currency quantities are inherently exact. If you're doing epsilon comparisons on currency quantities, you are making a fundamental ontological error.
Re:Why does 0.1 and 0.2 = 0.30000000000000004? by CamperBob2 on Wednesday February 08, 2023 @03:38PM (#34714674)
Nobody gives a hoot about 0.000001 cents. Round to the nearest 1/100 cent after adding or subtracting, and you will be fine in 99.99999% of applications.

The cardinal sin isn't using doubles for currency; it's using them without understanding either the tool or the job that you're asking the tool to perform.

Re:Why does 0.1 and 0.2 = 0.30000000000000004? by wyager on Wednesday February 08, 2023 @06:48PM (#34717487)
You've clearly never worked with accountants.
Re:Why does 0.1 and 0.2 = 0.30000000000000004? by CamperBob2 on Wednesday February 08, 2023 @08:11PM (#34718336)
[Citation needed]
Re:Why does 0.1 and 0.2 = 0.30000000000000004? by mths on Wednesday February 08, 2023 @10:11PM (#34719303)
You've clearly never worked with accountants. [1]

[1] https://news.ycombinator.com/item?id=34717487

Re:Why does 0.1 and 0.2 = 0.30000000000000004? by CamperBob2 on Wednesday February 08, 2023 @11:54PM (#34719919)
I don't know what I expected
Re:Why does 0.1 and 0.2 = 0.30000000000000004? by 8n4vidtmkvmk on Thursday February 09, 2023 @12:16AM (#34720054)
I've been using doubles for currency knowing full well that i probably shouldn't. for 8 years now. so far I've only noticed being off by a cent here and there. yep.. just don't care. will cost more than a penny to fix it now.
Re:Why does 0.1 and 0.2 = 0.30000000000000004? by lmm on Wednesday February 08, 2023 @10:49PM (#34719536)
Depends what you're doing with them. A value at risk calculation gives you a currency-dimensioned result that's hard to represent exactly, for example.
Re:Why does 0.1 and 0.2 = 0.30000000000000004? by wyager on Thursday February 09, 2023 @09:26AM (#34724354)
Yes, a more precise statement is "exact currency amounts form a group under addition" - once you depart from group operations (e.g. multiplication by non-integral scalars) you can start to consider floats.