开发者

String formatting: less decimals in %f float? [duplicate]

This question already has answers here: Make a float only show two decimal places 开发者_开发问答 (13 answers) Closed 8 years ago.

Well, I am using %f for displaying float values in my string. However, the values are too accurate (around 6 decimal digits after the point). I'd like to only display 1 decimal. But how?


%0.2f or some other number after the decimal point.


NSLog(@"%0.1f", floatThing);

I think that should work. For more decimals change 0.1 to 0.2, 0.3, 0.4 ... etc.


[NSString stringWithFormat:@"%.DECIMAL_PRECISION_NUMBER_HEREf", someFloat]


http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265

and

http://pubs.opengroup.org/onlinepubs/009695399/functions/printf.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜