What the actual fuck.
PHP, why can't money_format() round properly? round() and number_format() works fine, why is money_format() doing it wrong half the time?
If you have a number with 3 digits after the dot (e.g. 0.005) and the last digit is 5; then money_format will fail to round up that number when rounding to two digits - but only half the time!
That is, half of the numbers between 0 and 1 that are on the form 0.xx5 get rounded down, and the other half gets rounded up. I counted.
@bthall @zatnosk IEEE-754 (the floating point standard) is a masterpiece, full of tiny compromises about a few dozen obscure corner cases that come up when you start running a lot of numbers through computers. I made an implementation once at uni. it's an interesting standard to read through
one important takeaway is that it's not a suitable format for dealing with money. most languages will have a dedicated decimal or money format for that
Toots from Richmond, VA and around the world. Stick around for good vibes.