开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜