NSString scanning?
i am having NSString* str = @"1223.2212311"; i want to convert it 开发者_JAVA技巧as 1223.22(after floating point two chars),is it possible through NSString?i have to use NSScanner? any help please?
How about something like:
NSString* str = @"1223.2212311";
NSString* result = [NSString stringWithFormat:@"%.2f", [str floatValue]];
You should take a look at NSNumberFormatter.
If the strings aren't going to be localized, you can just use -[NSString floatValue]
to parse them.
精彩评论