标签:style blog io color os sp for strong on
代码:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. NSLog(@"--float-%@-",[self stringDisposeWithFloat:9.000899990000]); } //浮点数处理并去掉多余的0 -(NSString *)stringDisposeWithFloat:(float)floatValue { NSString *str = [NSString stringWithFormat:@"%f",floatValue]; int 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:@"."])//避免像2.0000这样的被解析成2. { return [str substringToIndex:[str length]-1];//s.substring(0, len - i - 1); } else { return str; } }
输出:
2014-12-02 17:01:08.253 浮点数处理并去掉多余的0[21460:60b] --float-9.0009-
标签:style blog io color os sp for strong on
原文地址:http://www.cnblogs.com/yang-guang-girl/p/4137967.html