针对普通除法无法得到精确值,引入精确除法运算
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
// public static void main (String[] args) throws java.lang.Exception
// {
// // your code goes here
// double num2 = 8.1 / 3;
// System.out.println(num2);
// }
public static void main(String[] args) {
BigDecimal b1 = new BigDecimal("8.1");
BigDecimal b2 = new BigDecimal("3");
BigDecimal divide = b1.divide(b2, 10, RoundingMode.HALF_UP);
System.out.println(divide);
}
}