If I do 0.3 - 0.2 it gives 0.9999999998 not 0.1 is there a way to make it give a percise decimal? Can't trust a calculator if it's not percise.
You could try this solution: https://30secondsofinterviews.org/#what-does-0-1-0-2-0-3-evaluate-to-
A solution to this problem would be to use a function that determines if two numbers are approximately equal by defining an error margin (epsilon) value that the difference between two values should be less than.
const approxEqual = (n1, n2, epsilon = 0.0001) => Math.abs(n1 - n2) < epsilon approxEqual(0.1 + 0.2, 0.3) // true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With