伙计们,我有一些非常小的浮点数,我想将它四舍五入到第一个不是零值。例如:
float toRound = 0.000002125231553;
toRound = //Operations//;
toRound == 0.000002;
你有什么想法吗?
伙计们,我有一些非常小的浮点数,我想将它四舍五入到第一个不是零值。例如:
float toRound = 0.000002125231553;
toRound = //Operations//;
toRound == 0.000002;
你有什么想法吗?
也许不是最好的方法。但它做你想要的;)
float s = 0.000322333123;
BOOL exit = 0;
NSString *x = [NSString stringWithFormat:@"%f", s];
for (int i = 0; i <= [x length]; i++) {
NSString *t = [x substringToIndex:i];
if ([t floatValue] == 0 || exit == 1) {
;;
}
else {
exit = 1;
s = [t floatValue];
}
}
NSLog(@"round: %f", s);
对数:圆形:0.0003