提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将String转换为Float
/*来自 NowJava.com*/ public class Main { public static void main(String[] args) { //1. Construct Float using constructor. Float fObj1 = new Float("10.4"); System.out.println(fObj1); //2. Use valueOf method of Float class. This method is static. String str1 = "1.4"; Float fObj2 = Float.valueOf(str1); System.out.println(fObj2); String str2 = "7.9"; float f = Float.parseFloat(str2); System.out.println(f); } }