开发者

Convert NSString to NSNumber

开发者 https://www.devze.com 2023-01-15 09:04 出处:网络
i get a nsstring from a nsdictionary via: inputString = [dataUsage valueForKey:@\"amount\"]; after that the string looks like: 23,56

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

精彩评论

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

关注公众号