I understand that computer can not represent non-integral numbers precisely. so when I add 2 doubles in java for example:
724.64d + 1000d
the console print out 1724.6399999999999
but why for 724.64d + 100d and 724.64d + 10000d
the console print out 824.64 and 10724.64 separately?
is there a way to know at what condition when I add the 2 doubles, the sum is the exact number ?
The reason why I ask is because that our old program use double to do calculation. and use double comparison to validate the numbers.
for example: let us say the total is 1849.64, all the inputs amounts added up must be equals to total which is 1849.64
input 1: 724.64
input 2: 1125
will not work, because the sum will be 1849.6399999999999
but if we input like this below will work, and the sum is 1849.64
input 1: 24.64
input 2: 1825
so how to find those combinations that work? Note, I do not have access to this specific very old program. when the validation failed, we have to manually find a walk around like the second inputs combination. Thanks.
double.