If I change d2 to 123.02 it gives the output as 866.05. Please let me know if this is called rounding error in java. If this topic has already been discussed , please give me the link. I'll take a look and understand.
Thank you All. In our Banking Product, they have made use of Double in upload Payroll files module. Now the total Debit amount is not equal to total credit amount for a few scenarios. It created all the problem. Thanks again for the links.
Tony Docherty wrote:You should never use floating point numbers to store financial values. You should always use integer types...
I would expand that to say you should never use a floating point type to store something that has discrete values. You wouldn't use a float to store the day of the month. You wouldn't use a float to store the number of students in a classroom. Since money is in discrete amounts, you should use some discrete variable type - like an int. This requires you to store values in pennies rather than dollars (or whatever currency equivalent you have), but that is trivial.
Joined: Aug 07, 2007
I would expand that to say you should never use a floating point type to store something that has discrete values.