Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert numbers into indicative string

I just want to know how can I can convert the numbers 1, 2 or 3 into First, second or Third ? Any help would be appreciated.

like image 761
Amit Singh Avatar asked Apr 05 '13 10:04

Amit Singh


2 Answers

Try this,

- (NSString *)getOrdinalTextFor:(NSInteger)number {

     NSNumber *numberValue = [NSNumber numberWithInteger:number];
     NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
     [numberFormatter setNumberStyle:NSNumberFormatterOrdinalStyle];

     return [numberFormatter stringFromNumber:numberValue];
}
like image 109
Balaji G Avatar answered Nov 02 '22 15:11

Balaji G


See this one may be it helps you,

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
    [formatter setNumberStyle: NSNumberFormatterSpellOutStyle];
    NSString* numberString = [formatter stringFromNumber:[NSNumber numberWithInt: 3]];
    NSLog(@"%@",numberString);
like image 1
Balu Avatar answered Nov 02 '22 16:11

Balu