Tag: objective-c

Objective-C number formatting with NSNumberFormatter

Posted by – December 11, 2008

Today I finished an article to a local magazine about mobile development, this article gives a small introduction on iPhone development with iPhone SDK, this article covers the development of a simple application that perform some meansure conversion. One of learned things was how to do number formatting with NSNumberFormatter like we have below:

1
2
3
4
5
6
7
8
NSNumber *result = [NSNumber numberWithFloat: 0.0];

NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
[numberFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[numberFormatter setDecimalSeparator:@","];
[numberFormatter setFormat:@"0.00000;0.00000;-0.00000"];
   
NSString resultText = [[[numberFormatter stringFromNumber:result];

In this example I’m setting the number format to show a float number with 5 decimal positions and using comma as decimal separator since this is the brazilian decimal separator. I could convert and format a NSNumber by just passing it as argument to stringFromNumber method of NSNumberFormatter instance. Not so different from Java, right?

Share

My first iPhone application and the next challenges

Posted by – April 23, 2008

Last sunday I finished the development of my first iPhone application, I could do this by using Xcode and Interface Builder, the last beta of iPhone SDK comes with good integration between these two tools, but there are some components missing on Interface Builder, like UIDatePicker and UISlider, I can bypass it for now.
More

Share