I have a question related to the JVM of java.
We have a double in the form of String and we want to parse it to double , so we wanted to check if the ','
parsea to '.'
correctly.
If you execute this piece of code:
System.out.println(String.valueOf(Double.parseDouble("98,71")));
The exception will skip:
java.lang.NumberFormatException: For input string: "98.71"
On the other hand, if you try to parse it in this way, no exception will be thrown:
double x = Double.parseDouble("23,34");
String result = String.valueOf(x);
System.out.println(result);
Let's say that the purpose of all this is to pair double a number in String format that is written with ','
and the number , when collecting the double , the ','
will be parsed by '.'
and later I will pause again the double to a String and the number will have a '.'
instead of a ','
.
It is clear that there are many ways to do this, but my goal with this question is to know why in the first System.out.println
that I have given you% error NumberFormatException
.