Gotta Be Careful with parseFloat

WARNING: This article features ANCIENT code! I'm keeping it online because it's interesting to see what I was thinking 10+ years ago. But you DEFINITELY should not be using this code. Anything you're reading about on this page has changed significantly since this was written.

Ran into this one today. Somebody forgot to remove the comma from a float:

parseFloat(1000);    // 1000, ok
parseFloat("1000");  // 1000, ok
parseFloat("1,000"); // 1, very bad!!!

The code in question was trying to parse a dollar amount from a popup form field.

It trimmed the "$" (which would cause a NaN and be noticed immediately), but it failed to remove the ",", which caused truncation. Unfortunately, since values over $1,000 are rare (but important!), and the destination was a screen full of other numbers, and it was one screen in a huge application, it took months before somebody with sharp eyes caught the bug in action.