Does parseFloat depend on the OS?

I am currently having some troubles with parseFloat(String). Here is some code to illustrate it:

pos.x = parseFloat("1,2345");
pos.x = parseFloat("1.2345");

The first one works against everything I found on the net correctly on my system (Win 7 64bit, german), but the second doesnt. It is the other way around for the one I am working together with, who lieves in the US and uses the US version of Win 7 64bit.

Is this possible, or am I just too stupid? It also seems as if converting a float to a string produces a comma on my system but a point on the us system...

Is there any better solution to this problem, then always checking the OS before parsing?


There's something called NumberStyles in .net. They are passed as flags to the parse function and should be able to deal with these kind of problems. Best you'd look them up on the msdn library.

Looks like you need to use the System.Globalization.NumberFormatInfo object in .NET. This lets you get the current (and correct) number separator (dot "." for US, comma "," for Europe) depending on the current machine's internationalization settings. You can then use this to parse numbers correctly, no matter what the language settings are on the OS.