What is the method for obtaining the remainder of a Big…
The BigDecimal class offers two methods for obtaining the remainder: remainder() and remainder(BigDecimal divisor).
- remainder() method: This method returns a new BigDecimal object that represents the remainder between the current BigDecimal object and 1. It is used as follows:
BigDecimal num = new BigDecimal("10.5");
BigDecimal remainder = num.remainder(BigDecimal.ONE);
System.out.println("余数:" + remainder); // 输出:0.5
- The remainder(BigDecimal divisor) method: this method returns a new BigDecimal object representing the remainder between the current BigDecimal object and the specified divisor. Here is how to use it:
BigDecimal num1 = new BigDecimal("10.5");
BigDecimal num2 = new BigDecimal("3");
BigDecimal remainder = num1.remainder(num2);
System.out.println("余数:" + remainder); // 输出:1.5