I have a double value as 47. I divide it by 60, but when I try to print it it shows 0.0000.
It should display 0.7858
How can I do that? Any help?
Here is my code:
int minutes = decimal * 60; float min = (minutes)/60; NSLog(@"%.4f",min);
Try this :
double decimal = 47.0 / 60.0; // Just so minutes is 47 double minutes = decimal * 60.0; double min = minutes / 60.0; NSLog(@"%.4f",min);
In Objective C (as well as C and C++), integer division is applied when both left and right operands are integers, so
minutes / 60 = 0. If you want a floating point operation, use floating points literals.