0

I know there's a lot of options to do this, and a lot of opinions too. I don't need something extremely secure, but still I want to be somewhat bullet-proof against wrong data.

What I do right now to check for int and float is :

mathFunctions = {
    isInt: function (value) {
        return ($.isNumeric(value) && value % 1 == 0);
    },

    isFloat: function (value) {
        return ($.isNumeric(value) && value % 1 != 0);
    }
};

Is this acceptable or I it's easily broken and I have to change/add more logic to it?

Leron
  • 9,546
  • 35
  • 156
  • 257
  • 3
    You don't need jQuery for that. – John Dvorak Jun 18 '13 at 13:04
  • So your definition of "float" is "number that isn't an integer"? So you can add two floats together and get something that isn't a float? – nnnnnn Jun 18 '13 at 13:07
  • @nnnnnn I have clear definition of float. What I ask is is my check good enough. – Leron Jun 18 '13 at 13:13
  • _"I have clear definition of float"_ - No, you didn't define it at all in your question, you expected us to infer it from the code you supplied even though you then asked if that code was acceptable. It seems a bit strange that you'd want to reject, say, `5.0` as not being a float, but if that is in fact your goal please say so explicitly. – nnnnnn Jun 18 '13 at 13:20
  • So... you know better way to check for float or you just want to point me the obvious - my code is not perfect, not even good. If it's the second.. ok, behave as you wish... – Leron Jun 18 '13 at 13:36
  • I'm genuinely willing to help you. My point isn't that there's something wrong with your _code,_ but that there's something wrong with your _question_ - you need to clearly explain (using words and maybe some examples, not using code) what you actually mean by "float". Until you do that there's no way to tell if your current code is the best way. – nnnnnn Jun 19 '13 at 02:04
  • Thank you. I appreciate your will to help! – Leron Jun 19 '13 at 05:15

0 Answers0