在Java中从Float转换为String

Given a float value and we have convert it into string.

给定一个float值,我们已经将其转换为字符串。

Java conversion from Float to String

Java从Float转换为String

To convert a Float to String, we use toString() method of Float class, it accepts a float value and returns the string value.

为了将Float转换为String ,我们使用Float类的toString()方法 ,该方法接受一个float值并返回字符串值。

Syntax:

句法:

    Float.toString(float);

Java代码将Float转换为String (Java code to convert a Float to String)

//Java code to convert afloat to String
public class Main {
    public static void main(String args[]) {
        float a = 10.23f;
        float b = 23.456f;

        //variable to store result
        String result = null;

        //converting float to string
        result = Float.toString(a);
        System.out.println("result (value of a as string) = " + result);

        result = Float.toString(b);
        System.out.println("result (value of b as string) = " + result);
    }
}

Output

输出量

result (value of a as string) = 10.23
result (value of b as string) = 23.456


翻译自: https://www.includehelp.com/java-programs/conversion-from-float-to-string-in-java.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值