Numbers don’t add up!
0.1 + 0.2 = 0.30000000000000004
Floating point numbers
How to fix it
Here’s an example of how I eliminate the rounding issues.
Essentially, I’m calculating the smallest number, which if multiplied by either number I’m adding together individually, would result in an integer. This is achieved by evaluating the number with the most numbers after the decimal point and what that value is. Once I have the multiplier, I use it on both the numbers I’m adding together, then do the addition, then divide by the multiplier to return the numbers back to their original decimal state.
By performing the addition on integers, no rounding issues occur.