title: Objective-c mile/km conversion
body: <p>In my iPhone application, the user can change the unit (km or mile) in the preferences.</p>
  
  <pre><code>[[NSUserDefaults standardUserDefaults] setObject:@"km" forKey:@"distanceUnit"];
  </code></pre>
  
  <p>or</p>
  
  <pre><code>[[NSUserDefaults standardUserDefaults] setObject:@"mile" forKey:@"distanceUnit"];
  </code></pre>
  
  <p>I save the distance only in km in my <strong>Core-Data.</strong> I work with <strong>int</strong>. So every time I get the distance i do the following:</p>
  
  <pre><code>if ([unit isEqualToString:@"km"]) {
  } else {
      intTotalKM = intTotalKM * 0.621371192;
  } 
  </code></pre>
  
  <p>And when saving the distance, I do the following:</p>
  
  <pre><code>if ([unit isEqualToString:@"km"]) {
  } else {
      intTotalKM = intTotalKM / 0.621371192;
  }
  </code></pre>
  
  <p>For example, without changing my distance, when I save and get it, I loose 1 or 2 km/miles.</p>
  
  <p>I loose precision because of <strong>0.621371192</strong> and because I'm using only <strong>int</strong>. I don't want to use double values. Do you have any ideas of how to deal with this problem?</p>
  
  <p>Edit: I wonder if there is any other way of conversion more appropriate for my situation.</p>
  
  <p>Thanks.</p>