【发布时间】:2012-10-17 11:23:44
【问题描述】:
您好,我想知道如何让我的 NSString 将 5.11 读取为 5.11 而不是 5.1。 我能做到这一点的必要条件是我从这个字段中读取英尺和英寸,而不是十进制格式。此代码适用于计算
CGFloat hInInches = [height floatValue];
CGFloat hInCms = hInInches *0.393700787;
CGFloat decimalHeight = hInInches;
NSInteger feet = (int)decimalHeight;
CGFloat feetToInch = feet*12;
CGFloat fractionHeight = decimalHeight - feet;
NSInteger inches = (int)(12.0 * fractionHeight);
CGFloat allInInches = feetToInch + inches;
CGFloat hInFeet = allInInches;
但它不允许您以正确的方式读取从 nstextfield 获取的值。
如果能帮助您从 nstextfield 读取正确信息,我们将不胜感激。 谢谢你
【问题讨论】:
-
这里有处理字符串的代码吗?我没有看到发布的代码有任何相关性。
标签: objective-c nsstring decimal nstextfield