I've got a float value from an accelerometer which looks like this:
-3.04299553323
I'd like to get -3.04 for example. Is there an easy way for rounding that float value?
Edit:
Rounding numbers in Objective-C
I know this is old post but just in case someone else is looking for a quick Two step option.
float old = -3.04299553323;
float new = [[NSString stringWithFormat:@"%.2f",old]floatValue];
Result = -3.04
The @"%.2f" will round to two decimal places. If you want three decimal places put @"%.3f" and so on.
Hope this helps!
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