Java – round to 2 decimal places

(Math.round(doubleValue*100))/100.0
(Math.round(doubleValue*100))/100.0

Is there a better way to round the decimal to 2 decimal places?

Solution

DecimalFormat format=new DecimalFormat("#.##");
DecimalFormat format=new DecimalFormat("#.##");
System.out.println(format.format(doubleValue));
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>