- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
@Brian White
Yeah I actually took a class on stuff like that. I don't deal with figures that have to be exactly correct so I didn't think about that. Especially the poster that talked about 0.1 not being able to be represented in binary. I remember that being an example in the class. So the idea the programmer was using was correct, just bad implementation
Admin
You know, I stared at that, and wondered to myself, that sounds SO familiar....
Then I felt dumb.
Admin
php also uses period as the strcat oper
Admin
The real WTF is the car payment. $400/month? Ouch!
http://www.daveramsey.com/etc/cms/don%27t_let_your_car_own_you_9565.htmlc
Admin
TRWTF is how many people responded after merely reading the bottom text and not using their brains.
Admin
$400/month is inexpensive?
Admin
$400/month for 3 months would be extremely inexpensive. $400/month for 26 years would be very expensive...
Admin
Now, if you knew what you were doing, you could write your own Javascript front-end, based on theirs, and find out if it's the Javascript that's broken, or the back-end that's serving the truncated identifier.
Admin
Admin
Admin
I agree. The main WTF here is that they are doing it client-side. Other than that, well it's just a mistake and I am sure we all do some on occasion.
Admin
Would you trust that system to take the correct amount out of your bank account? I wouldn't.
Admin
Your bank must love you! Try and think a bit one of these days. A penny off in the balance of an account. Not much of a problem (although 60 pennies x 20M customers = 12M, a decent chunk of change).
Now, what if the rounding error is applied to the monthly interest rate? Or if we stop being trivial, what if it occurs on the exchange rates where each transaction weights billions of USD? Would you like to pay the difference?
You can't afford this kind of lazy rounding if you deal with financial data. Period.
Admin
Not to mention the legal requirements in the playing with money field. Doing on the fly rendering is perfectly fine with having a few decimals wrong, most people wont see it anyways. Messing with money? Now that is quite different. ;) Lots of bean counters would rip your company to shreds for being lax with those calculations.
Admin
Admin
Oh what a wonderful idea....Let's have customers talk directly to technical teams and tell them how they should have done theuir job. That won't cause any problems.
(Quote Homer: "In case you can't tell I was being Sarcastic")
It is not surprising that the helpline is so unhelpful - they don't really understand what the caller is rabitting on about. That said, you would hope enough calls complaining about a 10 fold increase in the bill would ultimately lead to an investigation.
Allowing the caller to speak to a techo with his diagnosis is, however, not the answer - especially in this case where he was wrong anyway, the problem was not in applying the extra 0 (as a plethora of people have already stated).
Admin
Wha?
I didn't really follow your example (methinks you may have 'mfused yourself). Please explain this 0.5 again. There is not necessarily a need to round in this sort of an example, and I think it is common practice in many situations (where there is not a large string of calculations) to drop decimals lower than a cent.
Admin
Who Can't afford it? You object that the bank makes a significant profit, even though most customers wouldn't care (or at least wouldn't notice) the 60c. Is this Ethical? No. Is that the question? No.
The point I thought the OP was making, is that ripping one customer off 60 cents is hardly a critical problem. Most wouldn't notice, and many wouldn't care. The fact that the bank does this to 20M customers and makes $12M is irrelevant to the argument. I realise most peole hate banks (as do I), but the OP quite rightly points out that 60 cents is not (for most people) a significant problem (a minor inconvenience at best). The fact that the bank capitalises on this is a totally separate issue about ethics and fair trading.
Admin
I would expect that the client-side calculation is solely there for user feedback (though in that case it ought to be calculated when the input fields are changed, rather than requiring an extra mouse click).
The code looks like the victim of shotgun debugging; there were bugs but no-one could figure out how to actually fix them, so instead there's this ongoing sequence of half-baked attempts at applying "workarounds" with the hope that these bugs will eventually cancel each other out (adding zero didn't convert it to a number; oh, wait, sometimes it has the string "undefined" in it; let's try to parse an integer out of it; but after we do the calculation we lost the decimal - how did we get it back last time?....).
Admin
Javascript? A functional language? Puh-leeze, tacking some pseudo-closures onto a basically imperative scripting language is a long stretch from functional programming...
Admin
Suppose that, at the situation just before we round, the value is supposed to 4903.
Further suppose that the floating-point representation currently being used works out at around 4902.9999997
If you always floor the value, you'll end up knocking a cent off the value.
Admin
Read again and try to understand the issue here. The problem isn't the 60 cts. That 60 cts figure was a number AshG pulled out of his ***, to make the point that it didn't matter.
The problem is, it does matter. If you use floats with money transactions, you are in for trouble, and probably a lot more than just 60 cts a piece. Depending where the float was used, the difference could be billions of dollars. And as a programmer, you can't afford this kind of sloppiness.
Further, you assume that the rounding error would be in favor of the bank. What if it is the other way around? What if the bank is missing 12M and that after careful investigation it turns out that your sloppy rounding is responsible for that loss. So now the bank is suing your *** for 12M + damages...Do you still think it doesn't matter?
Admin
Those errors could be in either direction: 0.1 * 100 might end up either as 10.0000000000123 or as 9.9999999999876 (numbers pulled out of a hat, may not reflect actual floating-point calculations).
Math.floor() in JavaScript does not round to the nearest integer -- it rounds down to the largest integer less than the input. This means that 9.9999999999876 rounds to 9, not 10.
Adding 0.5 to the number corrects for this. Work it out in your head if you like: Math.floor(x + 0.5) returns 10 if x is between 9.5 and 10.5 (inclusive below, exclusive above).
Admin
It's hard enough trying to break through the fortress of support and into bug reporting when it's a company... Try doing it when it's a government department you work for. You'll probably not only be told there's no problem, you you'll probably be accused of causing it to start with.
Admin
FTFA:
Admin
<nit>JavaScript is not an implementation of ECMAScript, it's an extended pseudostandard with ECMAScript at its core. There are numerous JavaScript implementations, for instance SquirrelFish (Safari / WebKit), SpiderMonkey (Mozilla), Carackan (Opera) and many others.</nit>
Admin
Painfully amateurish.
Admin
It just goes to prove the old adage that when you have a problem, and you decide to solve it with a regular expression, you will suddenly find yourself with two problems.
Admin
It's all a matter of perspective -- variable assignment is just set!, objects are primitive associative arrays of closures (for methods) and values (for fields), and so forth.
The way I understood that talk is that closures is one of the only things in the language that ISN'T pseudo.
(Disclaimer: I have not read the formal ECMAScript specification).
Admin
Admin
Admin
That's a good analysis! Seriously.
Admin
Well, I don't write Web code, so I can't write my own front end. It might not even BE Javascript, but I think it is. Too bad the dialog box looks wonky and isn't resizeable and isn't moveable.
Admin
"Most wouldn't notice any many wouldn't care"? The bank regulators and state attorneys general would certainly care. Dealing with money has some legal ramifications.
Admin
Admin
Double data type offers you 15 digits. For the majority of money transactions such as purchases (100 bucks or less) this gives you 12 digits of precision, make it 11 since the last digit is always screwed up. It will take your system 10E11 transactions to make a 1 penny mistake.
Now, speaking of billion-dollar transactions. 3 digits of precision. 1000 transactions, 12-digits each, and you are short 1 dollar.
Once again, Holy crap!
Admin
Have you ever worked with accountants or auditors? Those people will not yield until the missing penny has been accounted for, on the very reasonable theory that if the system forgets pennies for no known reason, the reason should be found before one day the same bug will lead to a million going missing.
Doing exact arithmetic on integral numbers of cents is not difficult and therefore it is entirely reasonable to expect money-handing programs to do it -- there is simply no excuse not to. Otherwise we end on a slippery slope where little errors are expected because of rounding, and true bugs would not ever be caught before they became large, damaging, bugs.
Admin
What about IRS 1040? They always want you to round up your tiny income numbers to the closest dollar amounts. These IRS folks must be nuts!
Admin
Unless absolutely necessary I have a policy of not pointing out bugs on web pages anymore: my credit union has a link to an external site that displays the locations of reciprocal service centers - credit unions that operate under different names but are willing to provide notary services, cashiers' checks, check cashing services and so on to members of credit unions in that network. When on the external site an error message comes up saying something about a key being incorrectly configured. I sent a brief FYI to the contact email address and the girl responded by picking a fight with me telling me that I needed to speak with my credit union even though the problem was on her company's site. I asked her for the username/password so the admin at my credit union could log in and fix the error but she didn't grasp the notion and just told me to talk to my credit union again. I asked her why she was unwilling to tell her IT department that was an issue with their web page and again she told me that even though I was using their website to look up addresses the problem had to be with my credit union's webpage.
Admin
[quote user="AshG"]Have you ever worked with accountants or auditors? Those people will not yield until the missing penny has been accounted for, on the very reasonable theory that if the system forgets pennies for no known reason, the reason should be found before one day the same bug will lead to a million going missing.
Doing exact arithmetic on integral numbers of cents is not difficult and therefore it is entirely reasonable to expect money-handing programs to do it -- there is simply no excuse not to. Otherwise we end on a slippery slope where little errors are expected because of rounding, and true bugs would not ever be caught before they became large, damaging, bugs.[/quote]You mean, after 10 multi-million dollar transactions you'll miss a penny? [/quote]
I refer you to the explanation you quoted but apparently did not read. A missing penny is a sign of an error somewhere in your accounting practices. Such errors must be tracked down and fixed, or you will not be able to file your yearly operating report. Having an army of accountants and auditors try to track down that error costs considerably more than the penny.
Stop fixating on the monetary size of the discrepancy itself and accept the fact of the world that no errors are allowed in accounting, and ANY error will cost you whatever it takes to fix it.
Admin
Income: $3,652,654,985,652.01 Expenses: $3,652,654,985,652.00
Auditor: Hmm, where's the extra penny coming from? CFO: Developer, fix it! Developer: Hmm... Update BalanceSheet set Expenses = Espenses + $.01; Commit; Everyone: Standing ovation, cheers, champagne.
Admin
Dude, it's += '0' NOT += 0
tricky tricky!
Admin
Maybe you weren't looking hard enough, or not looking at all. After all, $45843.58 looks very much like $45843.59. Or if your test framework is written just as sloppily and also using floating-point numbers, it'll happily make the same mistake...
Admin
That sounds very dodgy. Especially if that += $0.01 pushes the expenses to $3,652,654,985,652.02 (or leaves it unchanged because it's past the end of precision) due to the nature of floating-point and rounding. And the auditor will be "what's this transaction?!? There's no details so it must be something illegal".
(IANAA)
Admin
I will cease my foolish attempt to educate you.
Admin
Nope, you still don't get it. A double does not give you 15 digits of accuracy. A floating point number cannot even accurately represent 0.1. Ever. Even if you assign a billion bits to store it in. So you are potentially 10 cts off without even performing a single operation. And it starts adding up very quickly.
Floating point and money just doesn't work. That's why arbitrary precision arithmetic exists. If you're doing maths on money with floating point, you have major issues.
Admin
Wow, you guys are young! Apparently no one remembers the bad old days when the myth that javascript couldn't to arithmetic got started by html writers who didn't know what they were doing. Even I fell for it for a few weeks, before I figured out how utterly wrong it was. Back then, they would do all arithmetic by eval()ing expressions or adding strings like this, obviously the programmer of this monstrosity believed some ancient sample code and never bothered to test whether plain addition worked. I figured at least one person would remember this very persistent myth.
Admin
Try this in your favourite browser's top bar:
javascript:alert(8.7 - 4.5);
Mine (firefox 3.5) doesn't say 4.2
Admin
[GCC 4.3.2 [gcc-4_3-branch revision 141291]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
OMG!! Python can't do arithmetic!oneeleven!!