2

So when I convert a double to a string using something like this:

double number = 1.1;
text = [[NSString alloc] initWithFormat:@"%f", number];

The variable text ends up printing something like this: 1.100000. I realize that this is because of the way the computer stores the value however I need an easy way to remove those extra zeros and, if need be, the decimal as well if the number turns out to an integer.

Thanks!

Tyler Johnson
  • 927
  • 8
  • 24

1 Answers1

1

Try to look at NSNumber and NSNumberFormatter with it's usesSignificantDigits property. It is probably what you are looking for.

beefon
  • 3,194
  • 1
  • 21
  • 25
  • Hmm seems like what I want, but I can't get this to work. I'm a bit of a noob at Objective-C. Anyway I can a bit of example code? – Tyler Johnson Jul 09 '10 at 04:52