如何在目标c中将小数转换为八进制 [英] How to convert decimal into octal in objective c

查看:244
本文介绍了如何在目标c中将小数转换为八进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像我的问题,我如何将十进制转换为八进制的目标c?
可以帮助我吗?它是让我dizy

just like my question, How can i convert decimal into octal in objective c? can somebody help me? it's make me dizy

推荐答案

您必须初始化一个新的 NSString 对象使用正确的格式说明符。

You have to initialize a new NSString object using the right format specifier.

像:

Like :

int i = 9;
NSString *octalString = [NSString stringWithFormat:@"%o", i]; // %O works too.

这将创建一个自动发布的 NSString 对象,其中包含八进制字符串表示 i 。如果您从包含小数表示的 NSString
开始,您应该先检索该数字:

This will create an autoreleased NSString object containing octal string representation of i. In case you start from a NSString containing a decimal number representation, you should first retrieve the number using :

int i = [myDecimalNumberAsAString intValue];

这是链接到格式说明符引用。

Here is a link to the format specifiers reference.

希望这有助于。

这篇关于如何在目标c中将小数转换为八进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆