objective c - iOS round a float -


i have floating point number have more decimal digits, example:

float fres = 10.0 / 3.0; 

actually fres value 3.3333333333333 it's possible set example 2 decimal digits:

float fres = 10.0 / 3.0; // fres 3.333333333333333333333333 float fresok = funcround( fres, 2 ); // fresok 3.33 

thanks in advance

assuming you're looking correct function round number of digits, you'll find easiest following:

fresok = roundf( fres*100.0)/100.0; 

that multiply value 100 (giving 2 digits of significance), round value, , reduce magnitude started with.


Comments