Reputation: 1438
i currently have an integer int i
and its value is 60
i wish to divide this by 100
to get 0.60 but i cannot do this please help
int i = 60;
int x = 60 / 100; // Dosen't work should be 0.60 instead returns 0
Upvotes: 6
Views: 7313
Reputation: 349
int i = 60;
float x = (float)i/100.0f;
NSLog(@"%.2lf", x);
//this will print 0.60
Upvotes: 1
Reputation: 17445
You can get the correct value using the following method:
float x = 60 / 100.0f;
If you are looking for the value 0.60 you cannot assign it to an integer (whole number) type.
Upvotes: 6