Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 目标c和cocoa将十进制英尺转换为英尺和英寸?_Objective C_Cocoa_Decimal - Fatal编程技术网

Objective c 目标c和cocoa将十进制英尺转换为英尺和英寸?

Objective c 目标c和cocoa将十进制英尺转换为英尺和英寸?,objective-c,cocoa,decimal,Objective C,Cocoa,Decimal,我如何将5.5英寸转换成5英尺6英寸。我在xcode中使用objective c和xcode来完成这项工作 感谢您的任何帮助我认为没有任何本机功能可以做到这一点。无论如何,这会奏效的 CGFloat decimal = 12.5; NSInteger feet = (NSInteger)decimal; CGFloat fraction = decimal - feet; NSInteger inches = (NSInteger)(12.0 * fraction); NSLog(@"%f fe

我如何将5.5英寸转换成5英尺6英寸。我在xcode中使用objective c和xcode来完成这项工作


感谢您的任何帮助

我认为没有任何本机功能可以做到这一点。无论如何,这会奏效的

CGFloat decimal = 12.5;
NSInteger feet = (NSInteger)decimal;
CGFloat fraction = decimal - feet;
NSInteger inches = (NSInteger)(12.0 * fraction);
NSLog(@"%f feet %f inches", feet,inches);

我认为没有任何本机函数可以做到这一点。无论如何,这会奏效的

CGFloat decimal = 12.5;
NSInteger feet = (NSInteger)decimal;
CGFloat fraction = decimal - feet;
NSInteger inches = (NSInteger)(12.0 * fraction);
NSLog(@"%f feet %f inches", feet,inches);

谢谢你的工作,你能告诉我如何允许在nstextfield中输入这个吗。e、 g.如果我把5.11放进去,它会读作5英尺11英寸,而不是5.1英寸。您以前的代码非常适用于计算。我不熟悉mac开发,但我觉得您应该实现任何NSTextFieldDelegate方法,并将textfield内容替换为correct(使用上述代码计算)用户完成输入值后的值。Krishnabhada:委托方法实际上不是这样做的。请参阅NSFormatter。另外,我将int/float和formatting转换为使用NSInteger/CGFloat(32/64)。谢谢您的帮助,您还可以告诉我如何允许将其输入nstextfield。e、 g.如果我把5.11放进去,它会读作5英尺11英寸,而不是5.1英寸。您以前的代码非常适用于计算。我不熟悉mac开发,但我觉得您应该实现任何NSTextFieldDelegate方法,并将textfield内容替换为correct(使用上述代码计算)用户完成输入值后的值。Krishnabhada:委托方法实际上不是这样做的。请参阅NSFormatter。另外,我将int/float和formatting转换为使用NSInteger/CGFloat(32/64)。为了帮助您改进您的Google fu,我认为Krishnabhada的答案是正确的,因为Objective-C是“C有好处”。这意味着在寻找问题的解决方案时,你的范围可以远远超过Objective-C。为了帮助你改进谷歌fu,我认为Krishnabhada的答案是正确的,因为Objective-C是“有好处的C”。这意味着在寻找问题的解决方案时,您的范围可以远远超出Objective-C。