Development problem: BigDecimal division error Non-terminating decimal expansion; no exact representable decimal result.
Error code:
// result is the calculation result result=cigaretteNum1.divide(result1);
When there is an infinite decimal like 1/3 in the division, an error will be reported if you don’t specify a few decimal places to keep
Modified code:
// result is the calculation result result=cigaretteNum1.divide(result1, 2 ,BigDecimal.ROUND_HALF_UP);
Keep two significant digits and round up
Similar Posts:
- [Solved] Division Error: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
- java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal …
- ToFixed, toexponential, toprecision in JS
- [Solved] Mvel user-defined function error: duplicate function
- Python: __ new__ Method and the processing of typeerror: object() takes no parameters
- Tomcat Error: Invalid maximum heap size
- The entity type XXX is not part of the model for the current context.
- [Solved] mapper.xml Error: java.lang.AbstractMethodError: Method oracle/jdbc/driver/OracleResultSetImpl.getNString(Ljava/lang/String;)Ljava/lang/String; is abstract,
- Error in modifying data element data type [How to Solve]
- C# Unable to translate set operation when matching columns on both sides have different store types