Java中从Double到String的转换

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

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值