Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error convert string "10 000.00" to double in Java

I try to convert this string "10 000.00" to double with method Double.valueOf and I've a input format error:

java.lang.NumberFormatException: For input string: "10 000.00"

How to convert it to double?


1 Answers

You can use:

Double.valueOf(input.replaceAll("[ ]",""));

in order to remove spaces before trying to convert.

Example :

public static void main(String[] args) {
  System.out.print(Double.valueOf("10 000.00".replaceAll("[ ]","")));
}

Output :

10000.0
like image 142
Arnaud Denoyelle Avatar answered Dec 17 '25 00:12

Arnaud Denoyelle