title: iOS Objective-C How to get 2 decimal rounded float value?
body: <p>I have a</p>
  
  <pre><code>float a = 1412.244019;
  </code></pre>
  
  <p>and I need a to be rounded to the nearest second decimal like 1412.24000000. I understand that if i want to present a with only two decimals i use %.2f, but that is NOT the case. I need the new a for mathematical reasons as a float.</p>
  
  <p>I have tried a couple of methods found on stackoverflow without luck. The more obvious one i used, i mention below, but still had no luck using it. Can YOU see why the magic is not happening?</p>
  
  <p>PS: It does do the desired effect sometimes, NOT always, which gets me thinking... hmmm...</p>
  
  <p>Thanks in advance.</p>
  
  <p>Code:</p>
  
  <pre><code>float a = 1412.244019;
  NSLog(@"a is %f", a); //output a is 1412.244019
  a = [[NSString stringWithFormat:@"%.2f", a] floatValue];
  NSLog(@"a is %f", a); //output a is 1412.239990
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>SEEMS like when i am using the float a after the above surgery, it is considering it to be 1412.240000 eventhough the NSLog says differently... strange. 
  But i am getting what I want, so Kudos for wasted time chasing nothing :)</p>
  
  <p><strong>EDIT</strong> I would love to choose you all as correct answers, but since i can only choose one, i chose the first good answer with extra explanation (of the two last).</p>