Convert NSString to NSNumber
i get a nsstring from a nsdictionary via:
inputString = [dataUsage valueForKey:@"amount"];
after that the string looks like: 23,56
how can i convert this stri开发者_JAVA技巧ng into a nsnumber?
i have tried the following:
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle:NSNumberFormatterDecimalStyle];
NSNumber *number = [formatter numberFromString:inputString];
[formatter release];
but this does not work. I think the problem is, that the "delimiter" is a comma. How can i fix this?
regards, patrick
-[NSNumberFormatter setLocale:]
You could also use setDecimalSeparator:
, but setLocale:
will take care of that as well.
精彩评论