Tried as below
String d=new String(\"12.00\");
Double dble =new Double(d.valueOf(d));
System.out.println(dble);
Output: 12.0
But i
Use BigDecimal Instead of a double:
String d = "12.00"; // No need for `new String("12.00")` here
BigDecimal decimal = new BigDecimal(d);
This works because BigDecimal maintains a "precision," and the BigDecimal(String) constructor sets that from the number of digits to the right of the ., and uses it in toString. So if you just dump it out with System.out.println(decimal);, it prints out 12.00.