Home > Java > javaTutorial > body text

How to convert String type to double type in java

王林
Release: 2020-06-10 14:15:05
Original
14068 people have browsed it

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);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template