I
inspired
Based on advice provided on an earlier post, I am trying to use the
BigDecimal class. However, I`m having a fundamental problem.
In my application class, I have the following:
private static final BigDecimal LSBvalue = (new BigDecimal (180 *
( Math.pow(2, 1 - 15)))).setScale(5, RoundingMode.HALF_UP);
public static int convertToInt(BigDecimal degrees) throws
ArithmeticException
{
return (degrees.divide(LSBvalue)).intValue();
}
The simple call below:
BigDecimal AngleDegrees = new BigDecimal(0.9118);
int AngleBams = convertToInt(AngleDegrees);
results in the following exception:
java.lang.ArithmeticException: Non-terminating decimal expansion; no
exact representable decimal result.
at java.math.BigDecimal.divide(BigDecimal.java:1603)
at BamBam.Angle.convertToInt(Angle.java:47)
at BamBam.Angle.main(Angle.java:73)
I am new to BigDecimal and not sure what I am doing wrong. Can
anyone help?
Alan
BigDecimal class. However, I`m having a fundamental problem.
In my application class, I have the following:
private static final BigDecimal LSBvalue = (new BigDecimal (180 *
( Math.pow(2, 1 - 15)))).setScale(5, RoundingMode.HALF_UP);
public static int convertToInt(BigDecimal degrees) throws
ArithmeticException
{
return (degrees.divide(LSBvalue)).intValue();
}
The simple call below:
BigDecimal AngleDegrees = new BigDecimal(0.9118);
int AngleBams = convertToInt(AngleDegrees);
results in the following exception:
java.lang.ArithmeticException: Non-terminating decimal expansion; no
exact representable decimal result.
at java.math.BigDecimal.divide(BigDecimal.java:1603)
at BamBam.Angle.convertToInt(Angle.java:47)
at BamBam.Angle.main(Angle.java:73)
I am new to BigDecimal and not sure what I am doing wrong. Can
anyone help?
Alan