tags:

views:

457

answers:

1

Code CGFloat a=3.45378;

I want change the result to CGFloat a=3.45f; only 2 precision

I know how printf works. but i dont know how to do this just keep 2 precision.

+1  A: 

To lose the extra precision, and round to the nearest two decimals, follow these steps:

  • Multiply your number by 100 : 345.378
  • Round your number to the nearest integer : 345
  • Divide your number by 100 : 3.45
Tim Rupe
thanks, it is a alternative solution. But for sure it works great. thanks