There are times in the project where the numeric part is retained, such as 2 digits after the decimal point, and all data is processed in this format.
//retain 2 digits after the decimal point, all processed in this format, no 0DecimalFormat DF =NewDecimalFormat ("0.00"); //There is no decimal, or the fractional part isBigDecimal DB1 =NewBigDecimal (111); System.out.println (Df.format (DB1)); //The following is strange, whether it is a string representation, or a numeric representation, as long as no more than 111.085 will not be roundedBigDecimal DB2 =NewBigDecimal (111.085); SYSTEM.OUT.PRINTLN (Df.format (DB2)); //greater than 111.08, therefore, "five in"BigDecimal DB3 =NewBigDecimal (111.0851); System.out.println (Df.format (DB3));
Results:
111.00111.08111.09
Format processing of numeric data (reserved for n digits after decimal point)