我有这个代码:
double s = [year.text doubleValue]*31536000;
second.text=[[NSString alloc] initWithFormat:@"%2g", s];
当我尝试计算时,最终结果是3.1536e+07
如何在没有e+07
的情况下使结果31536000
?
如果
指数小于 -4 或大于或等于精度,则%g
和%G
转换分别以 %e
或 %E
的样式打印参数;否则,它们使用 %f
样式。
您应该使用 %f
.
double s = [year.text doubleValue]*31536000;
second.text=[[NSString alloc] initWithFormat:@"%f", s];
简单使用 %f。
NSString *str = [[NSString alloc] initWithFormat:@"%f", s];
second.text = str;
second
可能会导致字符串没有"e+07"
f
是因为我们正在使用浮点数。
你应该尝试:
double s = [year.text doubleValue]*31536000;
second.text=[[NSString alloc] initWithFormat:@"%lf", s];