[Solved] BigDecimal division error: Non-terminating decimal expansion; no exact representable decimal result.

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:

Leave a Reply

Your email address will not be published. Required fields are marked *