0 %

在Java中从Float转换为String

2026-01-09 06:22:45

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

Posted in 世界杯葡萄牙阵容
Copyright © 2088 2034年世界杯_足球中国世界杯预选赛 - qdhuaxue.com All Rights Reserved.
友情链接