【发布时间】:2011-04-20 10:43:20
【问题描述】:
测试用例:
NSLog(@"%f", M_PI);
NSLog(@"%@", [NSString stringWithFormat:@"%f", M_PI]);
NSLog(@"%@", [NSNumber numberWithDouble:M_PI]);
结果:
3.141593
3.141593
3.141592653589793
结论:
1) 通过 NSLog() 或 [NSString stringWithFormat] 打印提供了非常低的精度...
2) 通过 [NSNumber numberWithDouble] 打印提供了更好的精度...
我希望得到更接近原始值的结果:3.14159265358979323846264338327950288(定义在 math.h 中)
有什么线索吗?
【问题讨论】:
标签: iphone cocoa-touch double precision nslog