Home >Java >javaTutorial >How to convert String type to double type in java

How to convert String type to double type in java

王林
王林Original
2020-06-10 14:15:0514088browse

How to convert String type to double type in java

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn