Best way to parseDouble with comma as decimal separator?

Koerr :

Following is resulting in an Exception:

String p="1,234";
Double d=Double.valueOf(p); 
System.out.println(d);

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

dogbane :

Use java.text.NumberFormat:

NumberFormat format = NumberFormat.getInstance(Locale.FRANCE);
Number number = format.parse("1,234");
double d = number.doubleValue();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

decimal separator in woocommerce to be a comma

AngularJS: Change decimal separator to comma

Replace point decimal separator with comma

Format a decimal with comma as decimal separator and without thousands separator

Parsing numbers with a comma decimal separator in JavaScript

regex expression to match decimal numbers with comma as a separator

Show comma instead of point as decimal separator

Only add thousand separator before decimal comma

Thousand separator while typing and decimal (with comma)

Add comma separator to a numbers with 2 decimal points

NumericUpDown: accept both comma and dot as decimal separator

How to write a csv with a comma as the decimal separator?

Replace comma with decimal separator from TextField

Xamarin Forms Entry: Use comma as decimal separator

seq uses both comma and dot as a decimal separator

Read txt file with comma decimal separator in MATLAB

Convert a double to 2 decimal places with comma separator

bc: decimal separator comma vs. point

Google form regex for numbers with comma as decimal separator

Pyspark, how to write a df with comma as a decimal separator

Use pandas style using comma as decimal separator

Comma as decimal separator space as thousand separator C#

jQuery Validation Plugin: validate decimal number with comma as decimal separator

formatting decimal number to string with comma as decimal separator in racket

Treat Comma and Period as Decimal Separator in Navision Decimal Fields

Pasting decimal numbers in excel / comma and point decimal separator

How to replace decimal separator dot by decimal separator comma in formattable() package R?

Angular uses comma instead of dot as decimal separator after changing culture

Convert String with Dot or Comma as decimal separator to number in JavaScript