Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem occurs because you use pointers in <code>NSInteger</code> and <code>float</code>. I have modified your method with the implementation for both cm and inches, as follows:</p> <pre><code>- (NSString *)returnRightMetric:(NSString *)theMeasure typeOfMetricUsed:(NSString *)metricType { NSString *result = nil; if ([metricType isEqualToString:@"inches"]) { NSArray* theConvertion = [theMeasure componentsSeparatedByCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"’”"]]; NSInteger value1 = [theConvertion[0] intValue]; NSInteger value2 = [theConvertion[1] intValue]; float number = ((value1 * 12) + value2) * 2.54; result = [NSString stringWithFormat:@"%.02f cm", round(number * 100.0) / 100.0]; } else if ([metricType isEqualToString:@"cm"]) { float value = [theMeasure floatValue]; float number = value / 2.54; if (number &gt; 12.0) { result = [NSString stringWithFormat:@"%i’%i”", (int)floor(number / 12.0), (int)number % 12]; } else { result = [NSString stringWithFormat:@"0’%i”", (int)round(number)]; } } NSLog(@"result: %@", result); return result; } </code></pre> <p>Some Test:</p> <pre><code>[self returnRightMetric:@"5’11”" typeOfMetricUsed:@"inches"]; [self returnRightMetric:@"180.34 cm" typeOfMetricUsed:@"cm"]; [self returnRightMetric:@"0’11”" typeOfMetricUsed:@"inches"]; [self returnRightMetric:@"27.94 cm" typeOfMetricUsed:@"cm"]; </code></pre> <p>The output:</p> <pre><code>result: 180.34 cm result: 5’11” result: 27.94 cm result: 0’11” </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload