$3,415.3,900,000,000,003
(i.redd.it)
You're viewing a single comment thread. View all comments, or full comment thread.
Comments (27)
sorted by:
(Tries it.) Yep, still busted. From the 2+2=5 set comes "Help, I can't make my webpage subtract a constant from something with two decimal places." Hell's sake, if decimal math is so hard for you cut that part off and just make it two integers.
I was going to see if I could look at the javascript to see where they fucked it but I'm too much of a neophyte - after I hit my third tracking JS file instead of one that did actual work, I quit.
It's just a floating point calculation of input - 750.0 without rounding to the nearest two decimal digits. Fire up a python shell and do 4165.39 - 750.0 and you'll get the exact same result as the website.
So at best they did the cardinal sin of programming and didn't test it. I'm not a CS guy, but couldn't they work around this by multiplying the input by 100, using an int instead of a float, then subtracting 75000, making it a float again, then dividing by 100?
Potentially yes, though they'd have to be careful to not do any sort of conversion to floating point at all, including using library functions to convert a string to a floating point number. Simply multiplying by 100.0 gives you the same problem:
There's also a class of numeric algorithms called arbitrary precision arithmetic that can be used to provide exact results from calculations between arbitrarily large numbers. Less flexible (but also able to provide exact results within the constraints of the size of the data type) are what they call "decimal data types" provided by some programming languages.
I maintain a small and obscure piece of open source financial software as a hobby project, and getting this stuff exactly right (which I'm sure I'm not, despite my best efforts) is a pain.