Given a double value and we have to convert it into string.
给定一个双精度值,我们必须将其转换为字符串。
Java conversion from Double to String
Java从Double转换为String
To convert a Double to String, we use toString() method of Double class, it accepts a double value and returns the string value.
为了将Double转换为String ,我们使用Double类的toString()方法 ,该方法接受一个double值并返回字符串值。
Syntax:
句法:
Double.toString(double);
Java代码将Double转换为String (Java code to convert a Double to String)
//Java code to convert a double to String
public class Main {
public static void main(String args[]) {
double a = 10;
double b = 20;
//variable to store result
String result = null;
//converting double to string
result = Double.toString(a);
System.out.println("result (value of a as string) = " + result);
result = Double.toString(b);
System.out.println("result (value of b as string) = " + result);
}
}
Output
输出量
result (value of a as string) = 10.0
result (value of b as string) = 20.0
翻译自: https://www.includehelp.com/java-programs/conversion-from-double-to-string-in-java.aspx