Am trying to code a Java calculator. Am running into some NumberFormat exceptions when trying to compute the following:
99.9(4x/8+k)
The funny thing is that its giving me the error after I distribute 99.9 only if the product of 99.9 and "k" is greater than or equal to 1000. So, for values greater than 10. In my code I try to load a string variable with the sums of all the constants of an equation, it is then that the error occurs. Here's what the code looks like:
double constantSum = 0;
//create a stringtokenizer object and convert each token to a double as
//follows, then, add the double to constantSum
constantSum = constantSum + Double.valueOf(token);//the token comes
//from the stringtokenizer object
The input that Double.valueOf(token) receives is 1098.900 which is the product of 99.9 and 11, notice that the input has been rounded to the thousandths place by a NumberFormat object I initialized in the code.
any ideas on how to get rid of this NumberFormat exception
Here are the details of how the exception looks like: Exception in thread "main" java.lang.NumberFormatException: For input string: "1,098.900" at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043) at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
thanks