I need to parse String to Double, but with my current code i am getting exponential notation in it
String str = "10000000";
Double parsedString = Double.valueOf(str);
It's giving me 1.0E7. I need output 10000000
Any help?
I need to parse String to Double, but with my current code i am getting exponential notation in it
String str = "10000000";
Double parsedString = Double.valueOf(str);
It's giving me 1.0E7. I need output 10000000
Any help?
you can call a method for this.
Double parseStringToDouble = validate(str);
The definition of validate method will be
private Double validate(String s) {
try{
return Double.valueOf(s);
} catch(NumberFormatException nfe){
// you can throw your custom exception here.
}
}
With this you will not get any exponential notation.
This is the way Double
numbers are displayed. If you want to display number in a different way you have to format it:
System.out.printf("%.0f", number);