java - Decimal conversion - NumberFormatException -
i have
string number = 1.0e7;
i want numeric equivalent i.e display
double x = 10000000.0000
how can go it?
i have tried double number = double.valueof(number);
but getting java.lang.numberformatexception
.
to format number 4 decimals, use string.format("%.4f", num)
in following example:
public class k { public static void main(string argv[]) { string number = "1.0e7"; double num = double.valueof(number); system.out.println("double="+ num + " formatted double=" + string.format("%.4f", num)); } }
output:
string=1.0e7 formatted double=10000000,0000
as can see, locale uses ,
decimal separator.
Comments
Post a Comment