javascript - how do you get the integer value of a field? -


I had to use it to get an integer value of the field:

  var local = {}; Local.result = $ ('# myID'). Val (); Local.result = parseInt (0+ local.result); Local Return   

Question: Is it a best practice instead, like some kind of jQuery method that gives value or number 0 if it is not a value?

Let me more jQuery!

You should only make any strong efforts to use + val If you have a non-numeric value, and want to default to 0 on your original post like this:

 str  >  var num = + str || 0; JSFiddle:  

Related JS Ninja Tricks:

I'm not sure that you mean any float conversion. It seems that this is already an integer because otherwise you will not be able to do it on parseInt , okay?

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -