News for hackers. Stuff that matters.
Re:Your balance is $0.30000000004 by vivan on Tuesday February 18, 2020 @10:17AM (#22356619)
You would think that this is a fairly rookie error and that big companies would know better, but I regularly see this on Uber: https://i.imgur.com/qDACtG0.png
Re:Your balance is $0.30000000004 by aeyes on Tuesday February 18, 2020 @11:42AM (#22357312)
Uber does not use float for money but the internal representation is converted to something displayable in the API layer.

Normally strings are used, for example: https://developer.uber.com/docs/riders/references/api/v1.2/r...

Guess somebody messed up for this case.

Re:Your balance is $0.30000000004 by mason55 on Tuesday February 18, 2020 @12:13PM (#22357645)
Interestingly even in your link you can see that most of the money values (subtotal, total_fare, total_charged) are strings but for some reason total_owed is a float.

Presumably someone messed up but it wasn't caught in code review.

Re:Your balance is $0.30000000004 by vivan on Tuesday February 18, 2020 @12:10PM (#22357615)
In this case, the value is the "surge_multiplier", which is indeed a float: https://developer.uber.com/docs/riders/references/api/v1.2/e...
Re:Your balance is $0.30000000004 by ryandvm on Tuesday February 18, 2020 @10:49AM (#22356852)
On the surface one would think big companies should "know better". I mean, a large company is the accumulation of centuries or even millennia of career experience. Unfortunately, they also contain just as much accumulated nonsense and foolishness; and enough bureaucracy and organizational cruft to hide it forever.
Re:Your balance is $0.30000000004 by saagarjha on Tuesday February 18, 2020 @11:04AM (#22356983)
Plus there’s the issue that the career experience isn’t evenly distributed, so you can often have people implementing features without the background necessary to do them right.
Re:Your balance is $0.30000000004 by mark-r on Tuesday February 18, 2020 @11:50AM (#22357388)
A large company is the accumulation of a large number of people, some of who will know better and some of who will not. Hopefully the company is organized such that the people who know will be in a position to catch those kind of errors, but that's not guaranteed.
Re:Your balance is $0.30000000004 by raxxorrax on Tuesday February 18, 2020 @10:59AM (#22356932)
browser console:

(1.005).toFixed(2)

(1.005).toFixed(20) reveals the problem.

Math.round(1.005 * 100) // wrong

In the end these conversion errors are not solvable in any language, so you have to "cut off" somewhere. There are different approaches to this.

Wasn't there a case where programmers stole the "wrong" cent and wasn't The Office a persiflage on that?

Re:Your balance is $0.30000000004 by vivan on Tuesday February 18, 2020 @11:02AM (#22356966)
That was the main plot of Office Space.

https://www.imdb.com/title/tt0151804/

Re:Your balance is $0.30000000004 by rstupek on Tuesday February 18, 2020 @12:08PM (#22357596)
Re:Your balance is $0.30000000004 by mark-r on Tuesday February 18, 2020 @02:24PM (#22359379)
According to Snopes, there was a third: Hackers.

https://www.snopes.com/fact-check/the-salami-technique/

Re:Your balance is $0.30000000004 by aidenn0 on Tuesday February 18, 2020 @12:35PM (#22357981)
Yeah. Underrated movie, actually.
Re:Your balance is $0.30000000004 by raxxorrax on Tuesday February 18, 2020 @02:00PM (#22359081)
Ah yes, I meant Office Space. Old but great movie.
Re:Your balance is $0.30000000004 by davedx on Tuesday February 18, 2020 @11:43AM (#22357316)
> In the end these conversion errors are not solvable in any language

Not true at all.

Ruby has BigDecimal: https://ruby-doc.org/stdlib-2.5.1/libdoc/bigdecimal/rdoc/Big...

.NET also has a Decimal type.

I've worked on salary calculation applications and e-commerce platforms, and found that language choice makes a big difference.

Re:Your balance is $0.30000000004 by raxxorrax on Tuesday February 18, 2020 @01:57PM (#22359035)
With insolvable i meant just the technical restrictions of floating point numbers. There are of course solutions. But there is just the fact that binary numbers with discrete length can only be mapped to so many numbers.

If you use numbers directly in exponential form in vanilla javascript, you already get better results.

Re:Your balance is $0.30000000004 by mark-r on Tuesday February 18, 2020 @11:46AM (#22357347)
It's not that they're not solvable, it's just that you have to go out of your way to use the proper type or library. The default floating point type still has problems.
Re:Your balance is $0.30000000004 by daxelrod on Tuesday February 18, 2020 @12:47PM (#22358142)
Important caveat: BigDecimal is arbitrary-precision, not infinite-precision. Using it still requires you to think about the precision of each number you operate on.
Re:Your balance is $0.30000000004 by mark-r on Tuesday February 18, 2020 @11:44AM (#22357327)
The story I heard is that the first time this was attempted in real life, the account balance grew so fast that it attracted attention and they were caught.
Re:Your balance is $0.30000000004 by tonyedgecombe on Tuesday February 18, 2020 @04:03PM (#22360383)
I've actually seen it on a statement from my bank.