What do you get for NSLog (@ "%. 3g", 1.12345)?
I did some tests, and as far as I understand, your question is on the right track. These are my results:
NSLog(@"%g", 1.000000); => 1
NSLog(@"%g", 1.123456789); => 1.12346
NSLog(@"%.1g", 1.123456789); => 1
NSLog(@"%.2g", 1.123456789); => 1.1
NSLog(@"%.3g", 1.123456789); => 1.12
NSLog(@"%.4g", 1.123456789); => 1.123
To get what you want, use @ "%. 4g".
source
share