If we want to convert String type data to Double type, we can use the Double.parseDouble() method to achieve this.
For example, we now want to convert the String type data "6.145" to the Double type and retain two decimal places. The implementation method is:
(Video tutorial recommendation: java video Tutorial )
The specific code is as follows:
String a = “6.145”; Double d= Double.parseDouble(a); DecimalFormat df = new DecimalFormat(“0.00”); String s = df.format(d);
The final variable s output is 6.15 (rounded).
Recommended tutorial: java entry program
The above is the detailed content of How to convert String type to double type in java. For more information, please follow other related articles on the PHP Chinese website!