Skip to content
Advertisement

Best way to parseDouble with comma as decimal separator?

Because of the comma used as the decimal separator, this code throws a NumberFormatException:

JavaScript

Is there a better way to parse "1,234" to get 1.234 than: p = p.replaceAll(",",".");?

Advertisement

Answer

Use java.text.NumberFormat:

JavaScript

Updated:

To support multi-language apps use:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement