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