How to round 0.0 to 0.00 in Java?
•
Java
I use the following functions
float val=0.0; DecimalFormat toTheFormat = new DecimalFormat("#.##"); float value=Float.valueOf(toTheFormat.format(val));
But it is not suitable for all conditions, such as "0.0" is still "0.0" Its scale cannot reach "0.00"
Solution
use
DecimalFormat toTheFormat = new DecimalFormat("0.00");
Round to 2 significant digits
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
二维码