In continuing my question from yesterday, I have the following code:
function VAL(str) {
// IF LEFT(str,1) IN('0,1,2,3,4,5,6,7,8,9,.) THEN
return parseFloat(str);
return 0;
}
function LEFT(str,n) {
if (n <= 0) return "";
if (n >= str.length) return str;
return str.substring(0,n);
}
Q: How do I write the commented line above such that it says “IF the first character is 0 or 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9 or period, then return parseFloat(str)”?
You don’t need that check. If the first character is not a digit, then
parseFloatreturnsNaN.