Test case:
NSLog(@"%f", M_PI);
NSLog(@"%@", [NSString stringWithFormat:@"%f", M_PI]);
NSLog(@"%@", [NSNumber numberWithDouble:M_PI]);
Results:
3.141593
3.141593
3.141592653589793
Conclusions:
1) Printing via NSLog() or [NSString stringWithFormat] provide a very low precision...
2) Printing via [NSNumber numberWithDouble] provides a better precision...
I would have expected to get a result much closer to the original value: 3.14159265358979323846264338327950288 (as defined in math.h)
Any clues?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…