Reputation: 1709
In my app i am using this to calculate a number:
double result = ((a * a) + (b * b) - (2 * a * b));
If a for example a = 2 and b = 3.9, then the result should be 3.61. However, when I display "result" i get the number 3.610000000000001.
What is wrong here? How can I correct this error?
Upvotes: 0
Views: 258
Reputation: 20944
You can format your output value by using the following construct:
String result;
twoDForm = new DecimalFormat("#0.00");
result = twoDForm.format(value);
After this, in result you will have your value in X.XX format
Upvotes: 3