Round float values accurately with output required decimal point in Objective-C -
how round float value
1.449567
accurately.
the output value should required decimal point floate value.
output should this:
for 1 decimal point **f=1.5** 2 decimal point **f=1.45** 3 decimal point **f=1.450** 4 decimal point **f=1.4496**
i'd recommend looking using nsnumberformatter.
example:
float roundedvalue =1.45999f; nsnumberformatter *formatter = [[nsnumberformatter alloc] init]; [formatter setmaximumfractiondigits:1]; [formatter setroundingmode: nsnumberformatterrounddown]; nsstring *numberstring = [formatter stringfromnumber:[nsnumber numberwithfloat:roundedvalue]];