Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Round floating value to .1 (tens place) [duplicate]

Possible Duplicate:
How can I round a float value to 2 post decimal positions?

Lets say I have a double number of 3.46. How do I round it to 3.50? I tried

NSLog(@"res: %.f", round(3.46)); 

but it return 3.

like image 212
user1688346 Avatar asked Feb 18 '23 22:02

user1688346


1 Answers

Do some calculations....

float f=3.46;
float num=f+0.05;//3.51
int intNum=num*10;//35
float floatNum=intNum/10.0;//3.5

NSLog(@"res: %.2f", floatNum); //3.50
like image 196
Anoop Vaidya Avatar answered Mar 05 '23 09:03

Anoop Vaidya