开发者

NSString scanning?

开发者 https://www.devze.com 2023-01-05 09:29 出处:网络
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?H

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.

0

精彩评论

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