Today, when debugging a java program, the following exception error message appears:
java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result。
The error statements are as follows:
one |
|
If you use BigDecimal to do Division in Java, you must pass the second parameter in the divide method, and the definition must be accurate to a few decimal places. Otherwise, if the result is infinite circular decimal without integer division, the above exception will be thrown
solutions
one |
|
Note that there are two overloaded methods for this divide method. One is to pass two parameters, and the other is to pass three parameters
Two parameter method:
@Param divisor value by which this {@ code BigDecimal} is to be divided
@Param rounding mode rounding mode to apply
The method of three parameters is as follows
@Param divisor value by which this {@ code BigDecimal} is to be divided. Incoming divisor
@ param scale of the {@ code BigDecimal} quotient to be returned
Similar Posts:
- [Solved] Division Error: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
- [Solved] BigDecimal division error: Non-terminating decimal expansion; no exact representable decimal result.
- ToFixed, toexponential, toprecision in JS
- [Solved] Operator overload must take either zero or one argument error
- [Solved] Java Call Error: java.lang.IllegalArgumentException: wrong number of arguments
- Python Error-TypeError:takes 2 positional arguments but 3 were given
- Laravel uses group by to report errors [How to Solve]
- [Swift] an error occurs when passing parameters using alamofire
- Django path Error: ‘Specifying a namespace in include() without providing an app_name ‘
- [Solved] Error: error c2678: binary ‘<', no left operand operator (or no acceptable conversion) that accepts type 'const a' was found