I want to know if there is a simple function that I can use such this sample.
I have a
float value = 1.12345;
I want to round it with calling something like
float value2 = [roundFloat value:value decimal:3];
NSLog(@"value2 = %f", value2);
And I get “1.123”
Is there any Library or default function for that or I should write a code block for this type of calculations?
thank for your help in advance
Using
NSLog(@"%f", theFloat)always outputs six decimals, for example:Output:
In other words, you will never get
1.123by usingNSLog(@"%f", theFloat).Cut-off after three decimals:
Output:
Round to three decimals (using
roundf()/lroundf()/ceil()/floor()):Output:
Round to three decimals (dirty way):
Output: