Here's a code snippet that increments by 0.001 on each loop. However, after a certain point, we want to display only two decimal places instead of three. For example, when the value reaches 0.01 on the 10th loop, we only want to show two numbers past the decimal.
var Num = 0.000;
for (var s = 1; s <= 15; s++) {
Num += 0.001;
var NumX = Num.toFixed(3);
if (NumX % 10 === 0) {
NumX = Num.toFixed(2);
alert("working");
}
}
In the code above, an attempt was made to divide by 10 to achieve this behavior, but dividing decimals is tricky. Can someone provide guidance on how to modify this code? Thank you!