hi, i am having NSString* str = @"1223.2212311"; i want to convert it as 1223.22(after floating point two chars),is it possible through NSString?i have to use NSScanner? any help please?
+2
A:
How about something like:
NSString* str = @"1223.2212311";
NSString* result = [NSString stringWithFormat:@"%.2f", [str floatValue]];
flitzwald
2010-06-30 11:11:39
+1 this is the proper way to do this.
Dave DeLong
2010-06-30 17:58:38
A:
If the strings aren't going to be localized, you can just use -[NSString floatValue]
to parse them.
Jonathan Grynspan
2010-06-30 17:54:39
Anything presented in the UI should be ready for localization. Your customers in France want to see a , symbol for the decimal. If you use NS numberFormatter you get that for free.
falconcreek
2010-07-08 03:14:16
This is a question about *parsing* a string into a float, not displaying a float as a string.
Jonathan Grynspan
2010-07-08 17:05:13