Turn from:Java float retains two decimal places or decimal places
Method 1: Use Math.Round to calculate the number format that is returned here.
float price=89.89;int itemnum=3;float totalprice=price*itemnum;float num= (float) (Math.Round (totalprice*100)/100); /If the exact 4-bit is required *10000 then/10000
Method 2: Return with DecimalFormat in string format. The class is fully encapsulated in decimal. Like the% number, thousand bits, decimal precision. Scientific calculation.
float Price=1.2;decimalformat decimalformat=new DecimalFormat (". 00");//character format of the constructor method if the decimal place is less than 2 bits, it will be filled with 0. String P=decimalfomat.format (price);//format returns a string
I think the second way is to show the amount in the foreground. The reason is simple in string format.
Java float retains two decimal places or decimal places