My question might be silly, and I actually have a workaround to solve this issue. But I'm still interested in why it happens. I have two numbers in my typescript file. Here is their definition.
mAlarmValue:number;
levelValue:number;
In my HTML input box which I also set the attribute type="number", I filled a number for mAlarmValue. After that, I did a comparison between those two numbers. Here is what I did.
console.log('Value =',this.mAlarmValue);
console.log("levelValue=",this.levelValue);
if (this.mAlarmValue <= this.levelValue) {
console.log("true");
}
And this is the actual console output.
Value = 10
levelValue= 5
true
Apprently 10 is greater than 5, but the result showed otherwise. My workaround is to convert the number to string and then convert it back to number.
console.log('Value =',this.mAlarmValue);
console.log("levelValue=",this.levelValue);
if (parseFloat(this.mAlarmValue.toString()) <= this.levelValue) {
console.log("true");
} else {
console.log(false)
}
Now it shows the correct result.
Value = 10
levelValue= 5
false
Does anyone have idea what's going on here? Thanks for your time.