1
CGFloat result=100/126;
NSLog(@"%0.5f",result);

the output of above code is 0.00000 but when i check it on calculator then the value is 0.79365. what is the problem

Iqbal Khan
  • 4,587
  • 8
  • 44
  • 83

2 Answers2

6

The problem is as both operands of division are integers, integer division is performed and its result is 0. To get proper value you need to make sure that at least one of your operands is floating point number:

CGFloat result=100.0f/126;
Iqbal Khan
  • 4,587
  • 8
  • 44
  • 83
Vladimir
  • 170,431
  • 36
  • 387
  • 313
1

May be because your variables are integers. Do this

CGFloat result=100.0/126.0;
NSLog(@"%0.5f",result);
Neo
  • 2,807
  • 1
  • 16
  • 18