Hello I am trying to build a function in javascript to check if a decimal number is multiple of another decimal number:
var num1 = 0.0002;
var num2 = 0.0001;
var remainder = (num1 % num2);
console.log(remainder);
if (remainder === 0) {
console.log('️ num1 multiple of num2'); //IF remainder is zero, so num1 is multiple of num2
} else {
console.log('⛔️ num1 NOT multiple of num2');
}
But when the num1 is 0.0003, 0.0004, 0.0005, 0.0006, 0.0007, etc is not working. In this cases the result is 0.00009999999999999996
num1 = 0.0008
is working
Why this happens and how to fix?