[Code Note] floating point number processing and removing excess 0, code note floating point number
I. Code.
-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. NSLog (@ "-- float-% @-", [self stringDisposeWithFloat: 9.000899990000]);} # pragma-mark-functions // floating point number processing and removing extra 0-(NSString *) stringDisposeWithFloat :( float) floatValue {NSString * str = [NSString stringWithFormat: @ "% f ", floatValue]; long len = str. length; for (int I = 0; I <len; I ++) {if (! [Str hasSuffix: @ "0"]) break; else str = [str substringToIndex: [str length]-1];} if ([str hasSuffix :@". "]) // avoid parsing 2.0000 to 2. {// s. substring (0, len-I-1); return [str substringToIndex: [str length]-1];} else {return str ;}}
2. output.
09:53:45. 765 floating point number processing and remove the excess 0 [1554: 47555] -- float-9.0009-2015-10-16 09:53:48. 824 floating point number processing and removing excess 0 [1554: 47619] Terminating since there is no system app.