Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting NSDecimalNumber to NSString

I'm retrieving a key from an object that looks like this:

po obj
{
  TypeID = 3;
  TypeName = Asset;
}

The key value is being retrieved like this:

NSString *typeId = (NSString*)[obj objectForKey:@"TypeID"];

Rather than typeId being an NSString, it is an NSDecimalNumber. Why is that?

How do I convert it to an NSString?

like image 646
4thSpace Avatar asked Apr 04 '10 05:04

4thSpace


1 Answers

You need to use the stringWithFormat function:

NSString *typeId = [NSString stringWithFormat:@"%@", [obj objectForKey:@"TypeID"]];

or stringValue:

NSString *typeId = [[obj objectForKey:@"TypeID"] stringValue];
like image 191
Jeff B Avatar answered Oct 09 '22 17:10

Jeff B