Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  150] [ 2]  / answers: 1 / hits: 42781  / 12 Years ago, tue, october 2, 2012, 12:00:00

I have a question about the default behavior of JavaScript's parseFloat function in different parts of the world.



In the US, if you call parseFloat on a string 123.34, you'd get a floating point number 123.34.



If I'm developing code in say Sweden or Brazil and they use a comma instead of a period as the decimal separator, does the parseFloat function expect 123,34 or 123.34.



Please note that I'm not asking how to parse a different culture's number format in the US. I'm asking does parseFloat in Sweden or Brazil behave the same way it does inside the US, or does it expect a number in its local format? Or to better think about this, does a developer in Brazil/Sweden have to convert strings to English format before it can use parseFloat after extracting text from a text box?



Please let me know if this doesn't make sense.


More From » culture

 Answers
11

parseFloat doesn't use your locale's definition, but the definition of a decimal literal.



It only parses . not ,



I'm brazilian and I have to replace comma with dot before parsing decimal numbers.



parseFloat specification


[#82793] Monday, October 1, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hector

Total Points: 726
Total Questions: 103
Total Answers: 100

Location: Seychelles
Member since Mon, Jun 28, 2021
3 Years ago
;