Given the fact that real numbers behave the same way as in your case, I’m afraid there’s nothing to be done about it. You could plan it to avoid this, and create a space for performing equality checks on your double values.
Here are two plausible hacks:
1: [Tried this in a college project] To deal with numbers in the order of 10 ^ -4, use an integer and a coefficient value. Example: to store 1.2345, store as an integer 12345 and multiply as 10000. Now you can print correctly, and this also makes it possible to carry out equality checks.
2: If the accuracy of the double values is already known, you can use the offset. Example: if 2.109999 has an accuracy of 2 decimal places, use something like this: (int) ((2.109999 +.005) * 100). And then type accordingly.
But both of these hacks suggest the following:
1: You control the accuracy of the values. 2: you really need to print accurate values.
source share