I'm struggling with my counter code that is supposed to count from 0 up to a given number, but it seems to have issues with decimals. For example, if it's set to count to 4.5, it stops at 4.1 or when counting from 0 to 5.7, it stops at 5.1. I've tried troubleshooting the code but can't seem to pinpoint where the mistake may be. Can anyone offer any help or guidance?
Here is the relevant part of the code:
if (!this.valueCount){
this.value = 0;
let valueInterval = setInterval(() => {
if (this.value === this.value1){
clearInterval(valueInterval);
this.valueCount = false;
} else if (this.value < this.value1){
this.value++;
this.valueCount = true;
} else {
this.value--;
this.valueCount = true;
}
this.value =+ (this.value + 0.1).toFixed(1);
this.base.querySelector('#value .values').innerHTML = this.value;
}, 50);