Error Messages - 1 year ago 145

Java Question

I cant find why I got a

`java.lang.ArithmeticException: Invalid operation`

`public static String E (int exponent, String value){`

BigDecimal ten= new BigDecimal("10");

BigDecimal tempValue=new BigDecimal (value);

return tempValue.multiply(ten.pow(exponent)).toString();

}

Some of the exponents have values such as

`-27`

Thank you

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

If you are raising things to negative exponents, you must specify a `MathContext`

in `BigDecimal.pow(int, MathContext)`

so it knows how much precision to use -- otherwise, `BigDecimal`

will try to compute it to infinite precision, which is not possible for some values.

(Unless you can be *absolutely sure* that the operation you're doing has an exact result with a finite number of digits.)

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**