从CGFloat转换为NSString

时间:2015-07-23 11:45:20

标签: objective-c

我有一个Fraction(CGFloat),我想在Return返回NSString。

- (CGFloat)add:(Fraction *)addF {

    CGFloat num = self.numerator * addF.denominator + self.denominator * addF.numerator;
    CGFloat den = self.denominator * addF.denominator;
    return num/den;
}

viewDidLoad中:

Fraction *fra1 = [[Fraction alloc]initWithNumerator:4 denominator:3];

Fraction *fra2 = [[Fraction alloc]initWithNumerator:2 denominator:5];

结果:从1.733 ...到26/15

1 个答案:

答案 0 :(得分:3)

您需要将返回类型从MemorySafeUndeclaredThrowableStrategy更改为CGFloat,您可能还希望在执行此操作之前将分子和分母除以最大公约数(GCD)

NSString