| Blockland Forums > Modification Help |
| Strip Trailing Zeros |
| << < (2/4) > >> |
| Greek2me:
The new function works for floating point, everything. --- Quote from: Destiny/Zack0Wack0 on November 11, 2011, 10:35:38 PM ---For any number including floating points: %string $= %string * 1 --- End quote --- That's what I had originally but like Ichverbot (Iban?) said, that breaks when there's extra 0s at the end. |
| Destiny/Zack0Wack0:
--- Code: ---function isNumber(%value) { %dot = strPos(%value,"."); if(%dot == -1) return %value $= mFloatLength(%value,0); return %value * 1 $= mFloatLength(%value,strLen(%value) - %dot - 1); } --- End code --- EDIT: aaaaa just wait this worked before, let me fix it. EDIT: Fixed. This is what I get for mindless copy pasting. |
| Ichverbot:
It would be really kickin' rad if Badspot integrated some "isInt" / "isFloat" functionality engine-wise. Handling it manually is a massive hack. |
| Destiny/Zack0Wack0:
Also, this: --- Code: ---function typeOf(%value) { if(isObject(%value)) return "object"; %dot = strPos(%value,"."); if(%dot == -1 && %value $= mFloatLength(%value,0)) return "integer"; if(%dot != -1 && %value * 1 $= mFloatLength(%value,strLen(%value) - %dot - 1)) return "float"; return "string"; } --- End code --- EDIT: --- Quote from: Ichverbot on November 11, 2011, 11:33:45 PM ---It would be really kickin' rad if Badspot integrated some "isInt" / "isFloat" functionality engine-wise. Handling it manually is a massive hack. --- End quote --- isNull would be brilliantly useful. |
| Nexus:
I use this for isint --- Code: ---function isint(%x) { return (%x $= mfloor(%x)); } --- End code --- I have yet to come across any problems |
| Navigation |
| Message Index |
| Next page |
| Previous page |