数字格式化异常

Format numberFormat = new DecimalFormat("0.##");

Object obj = 0.0272727272727273;


String format1 = numberFormat.format(obj.toString());

System.out.println(Float.valueOf(format1));


Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Number
at java.text.DecimalFormat.format(DecimalFormat.java:505)
at java.text.Format.format(Format.java:157)
at com.jerry.test.Test1.main(Test1.java:14)


Object obj = 0.0272727272727273;

String format1 = numberFormat.format(obj);
System.out.println(Float.valueOf(format1));


正常

你可能感兴趣的:(数字格式化异常)