Integers on iphone becoming Floats on Android
I started developing an app on the iphone, and when I moved over to Android to check how things were coming out it looks like every integer is getting decimals, turning into floats. Even json responses containing just numbers turn into floats on the android. So… is it a bug?
4 Answers
-
Accepted Answer
Javascript doesn't have an integer type. It just displays it that way if it can. It actually has a Number type. Look at http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html
-
I can confirm this (although no idea about the iphone). I'm finding this whole float thing to be VERY annoying. I'm creating variables that represent seconds for use in timer objects. This is being output to the screen as a float (supposed to just be a plain int). I've tried doing parseFloat() on both the the variable definition and when I'm outputting the variable as the value for a string. It seems no matter what i do i just cant seem to get it to just be an int >:( This is beyond irritating.
I'm assuming that somewhere in the bowels of the titanium->java logic things are getting converted - since it doesn't seem to be a problem with the javascript parser (else parseFloat would have an effect). So yeah, I'm going to go with 'bug' on this one :(
-
Javascript doesn't have an integer type. It just displays it that way if it can. It actually has a Number type. Look at http://oreilly.com/javascript/excerpts/learning-javascript/javascript-datatypes-variables.html
-
I got this bug too. It is annoying. But found a workaround. First did a toString() on the variable and then did a split on '.' and displayed the first part of the array. This works for both Android and Iphone