We know that the double type will involve precision loss during processing, for example, double d = 100*1.005; the result of result d is 100.49999999999999. How can this problem be solved by DecimalFormat, it is used to round the double type as follows: DecimalFormat df = new DecimalFormat (pattern); String nums = df. format (value); pattern :". 00 "value: 100 * 1.005nums value: 100.50 commonly used semicolons of pattern: #, #0.00 (why do I need to use 0 digits? #, because if df. format (0). If # is used, 0 is displayed as null and the result is. if 0 is used, 0.00 is displayed.) For the pattern setting, refer to the following: Symbol Location Localized? Meaning0 Number Yes Digit # Number Yes Digit, zero shows as absent. number Yes Decimal separator or monetary decimal separator-Number Yes Minus sign, Number Yes Grouping separatorE Number Yes Separates mantissa and exponent in scientific notation. need not be quoted in prefix or suffix .; subpattern boundary Yes Separates positive and negative subpatterns % Prefix or suffix Yes Multiply by 100 and show as percentage \ u2030 Prefix or suffix Yes Multiply by 1000 and show as per mille limit (\ u00A4) prefix or suffix No Currency sign, replaced by currency symbol. if doubled, replaced by international currency symbol. if present in a pattern, the monetary decimal separator is used instead of the decimal separator. 'prefix or suffix No Used to quote special characters in a Prefix or suffix, for example, "'#" formats 123 to "#123 ". to create a single quote itself, use two in a row: "# o '''clock ".