I have this following if statement:
RG is “100” and max is “85”
if (RG == "" | RG > max) {
//Doesn't execute
}
Since RG isn’t “” and RG is larger than max why isn’t the code executing? I believed the operator was short circuiting (hence only the one pipe |) but changing it didn’t make any difference. My guess is that it is comparing literal strings – so how do I force javascript to treat them as floats?
Just to be clear I need both parts of the OR to be checked and only execute if either of them is true.
I take it then it originally looked like this:
We can ignore the first part because it’s false, so your question is why wasn’t
RG > maxtrue? And the answer is that “100” comes before “85” in the string collation order. Strings are not numbers, you don’t compare them numerically.If you want them to be floats as you said, you can make them numbers via
parseFloat(orparseIntas they look like integers, but you said floats, so…):I’ve done it inline there, but the odds seem high you’ll want to do it earlier and assign the result to variables, unless this really is the only place you’ll use the values as numbers.