I'm trying to truncate a double value to two decimal places. I tried using:
[highScoreLabel setText:[NSString stringWithFormat:@"Highscore: %.2f",finalTime]];
but I found that it rounds the number after 2 places. This makes the score I'm reporting to game center and the score displayed in app different. How can I cut off the rest of the decimal without rounding it?
@dasdom answer is great. But if you do not like implicit casting you can use
finalTime = trunc(finalTime * 100) / 100;
If you will receive an error that 'trunc' function is unknown - just import math.h header:
#import <math.h>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With