Reputation: 3487
How do I parse this Double in string "00034800"
into a Double value? The last 2 digits are actually decimal point, so the result I am looking for is 348.00
. Is there a such format I can use with Decimal Format?
Upvotes: 2
Views: 212
Reputation: 136152
you can parse it as
double d = Double.parseDouble("00034800") / 100;
and print it as
System.out.printf("%.2f", d);
Upvotes: 1
Reputation: 786291
Java Double has a constructor that takes a String.
You can do:
Double d = new Double("00034800");
And then
double myval = d.doubleValue() / 100.0;
Upvotes: 4
Reputation: 17329
Well...
String s = "00034800";
double d = Double.parseDouble(s) / 100.0;
System.out.println(new DecimalFormat("0.00").format(d));
Upvotes: 10