Code: Select all
f = float(s);
ret = f != 0;
if (!ret) {
// do some simple checks if need distinguish false and 0 value as input.
}
return ret;
Side effect it accept values like "12345 some text".
If you not need it, you can later check Something like that:
if (float(s) == float(s $ "9999")) die("Bad chars at end");
OFC in some edge cases like "1.00000000" it make false positive, but it good enough for most cases.
Can be improved as:
Code: Select all
f = float(s);
return f != 0 || f != float(s $ "999");
Or even:
Code: Select all
f = float(s);
return f != float(s $ "999");
Fit for most cases. except some really edge cases, when numbers specified too precise for float so append at end not change it.