Import java.io.*; Import java.text.*; Import java.math.*; Import java.util.*; gaojingdutest {public static void main (string[] args) {//double decimal-point control output double a=1113.141592653; DecimalFormat formatter1=new DecimalFormat ("#.000000"); System.out.println (Formatter1.format (a)); The decimal point control output String b= "1113.141592653" for BigDecimal type data; Method 1 BigDecimal bd1=new BigDecimal (b); DecimalFormat formatter2=new DecimalFormat ("#.000000"); System.out.println (Formatter2.format (Bd1.doublevalue ())); Method 2, the first parameter of the Setscale method in BigDecimal//is the number of precision digits we want to specify. Here I set it to 6 decimal places, but remember, if//rounded after the result of a few decimal digits is 0, it will be omitted, that is, 0 is not output, see the following test BigDecimal bd2=new BigDecimal (b); System.out.println (Bd2.setscale (6,bigdecimal.round_half_up). Doublevalue ()); Test System.out.println (); System.out.println ("The following is test:"); BigDecimal b0=new BigDecimal ("1.00000000"); System.out.println (B0.setscale (6,bigdecimal.round_half_up). Doublevalue ()); BigDecimal b1=new BigDecimal ("1.00000010"); System.out.println (B1.setscale (6,bigdecimal.round_half_up). DoublEvalue ()); BigDecimal b2=new BigDecimal ("1.00000020"); System.out.println (B2.setscale (6,bigdecimal.round_half_up). Doublevalue ()); BigDecimal b3=new BigDecimal ("1.00000030"); System.out.println (B3.setscale (6,bigdecimal.round_half_up). Doublevalue ()); BigDecimal b4=new BigDecimal ("1.00000040"); System.out.println (B4.setscale (6,bigdecimal.round_half_up). Doublevalue ()); BigDecimal b5=new BigDecimal ("1.00000050"); System.out.println (B5.setscale (6,bigdecimal.round_half_up). Doublevalue ()); BigDecimal b6=new BigDecimal ("1.00000060"); System.out.println (B6.setscale (6,bigdecimal.round_half_up). Doublevalue ()); BigDecimal b7=new BigDecimal ("1.00000070"); System.out.println (B7.setscale (6,bigdecimal.round_half_up). Doublevalue ()); BigDecimal b8=new BigDecimal ("1.00000080"); System.out.println (B8.setscale (6,bigdecimal.round_half_up). Doublevalue ()); BigDecimal b9=new BigDecimal ("1.00000090"); System.out.println (B9.setscale (6,bigdecimal.round_half_up). Doublevalue ()); /* Output results are as follows: 1113.141593 1113.141593 1113.141593 below for Test: 1.0 1.0 1.0 1.0 1.0 1.000001, 1.000001 1.000001 1.000001 *}}
--> the problem of high accuracy is indeed a big problem, but unfortunately this year.
PS: After writing, we found that Java also has such a way to control the output accuracy
System.out.printf ("%.6f/n", 0.1);
The output is: 0.100000