java.lang.ArithmeticException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • Monetary Calculation Pitfalls - Spring Framework Guru
    via by Unknown author,
  • bigdecimal Archives - Spring Framework Guru
    via by Unknown author,
  • BigDecimal throws ArithmeticException
    via Stack Overflow by Gozzah
    ,
  • Java BigDecimal divide
    via Stack Overflow by WhitneyChia
    ,
  • FULL PRODUCT VERSION : java version "1.8.0_31" Java(TM) SE Runtime Environment (build 1.8.0_31-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode) ADDITIONAL OS VERSION INFORMATION : Version 6.3.9600 A DESCRIPTION OF THE PROBLEM : BigDecimal.divide() throws an arithmetic exception regardless of the precision and rounding mode of the arguments. Error is Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result. at java.math.BigDecimal.divide(BigDecimal.java:1690) at em.EM.testDivide(EM.java:37) at em.EM.main(EM.java:42) Java Result: 1 STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : import java.math.BigDecimal; import static java.math.MathContext.DECIMAL128; public class EM { private static void testDivide(){ int divisor = 147_579; double dividend = 1530.5913281688415; BigDecimal bdDividend = new BigDecimal("1530.591328167000", DECIMAL128); double quotient = dividend / divisor; BigDecimal bdQuotient = bdDividend.divide(new BigDecimal( divisor, DECIMAL128)); System.out.printf("%11.9f; %11.9f", quotient, bdQuotient); System.exit(4); } public static void main(String[] args) { testDivide(); } } EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - quotient = 1530.591328167000/147_579 ACTUAL - Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result. at java.math.BigDecimal.divide(BigDecimal.java:1690) at em.EM.testDivide(EM.java:37) at em.EM.main(EM.java:42) Java Result: 1 ERROR MESSAGES/STACK TRACES THAT OCCUR : Exception in thread "main" java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result. at java.math.BigDecimal.divide(BigDecimal.java:1690) at em.EM.testDivide(EM.java:37) at em.EM.main(EM.java:42) Java Result: 1 REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- import java.math.BigDecimal; import static java.math.MathContext.DECIMAL128; public class EM { private static void testDivide(){ int divisor = 147_579; double dividend = 1530.5913281688415; BigDecimal bdDividend = new BigDecimal("1530.591328167000", DECIMAL128); double quotient = dividend / divisor; BigDecimal bdQuotient = bdDividend.divide(new BigDecimal( divisor, DECIMAL128)); System.out.printf("%11.9f; %11.9f", quotient, bdQuotient); System.exit(4); } public static void main(String[] args) { testDivide(); } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : There is no workaround, except possibly drink.
    via by Webbug Group,
    • java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result. at java.math.BigDecimal.divide(BigDecimal.java:1690) at prototype.CloneExample.main(CloneExample.java:24)

    Users with the same issue

    DavidDavid
    2 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    serious2monkeysserious2monkeys
    2 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,
    Unknown visitor
    Unknown visitor1 times, last one,