一、用format
String.format("%.2f",f)
二、用数学方式:
(float) (Math.round(value.getT_EXT4() * 100)) / 100
String.foramt中格式相关:
代码如下:
1 System.out.println(String.format("%01.2f", 0.3f)); 2 System.out.println(String.format("%02.2f", 0.3f)); 3 System.out.println(String.format("%03.2f", 0.3f)); 4 System.out.println(String.format("%04.2f", 0.3f)); 5 System.out.println(String.format("%05.2f", 0.3f)); 6 System.out.println(String.format("%06.2f", 0.3f));
输出:
1 0.30 2 0.30 3 0.30 4 0.30 5 00.30 6 000.30