2012-05-29 137 views

回答

5
BigDecimal bigDecimal = new BigDecimal("1.500000154"); 
bigDecimal.setScale(1, BigDecimal.ROUND_HALF_UP) 
String result - bigDecimal.toString(); 
+0

谢谢你的回复。我试着去做 – user1360797

3

这也为我工作:

String str = "1.5000000154"; 
DecimalFormat df = new DecimalFormat("##.#"); 
System.out.println(df.format(Double.parseDouble(str))); 

打印:

1.5

更多关于Decimal的信息格式可以获得here。如果有需要的话,这也需要整理。例如,1.5900000154,将导致1.6

相关问题