Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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?

— asked May 24th 2010 by Caio Iglesias
  • android
  • float
  • integer
  • iphone
0 Comments

4 Answers

  • 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 :(

    — answered October 1st 2010 by Alex Borisov
    permalink
    0 Comments
  • 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

    — answered December 20th 2010 by Deeksha Prabhakar
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.