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

问题描述

我需要写一些数字,例如:1> yek

I need to write numbers like:1>yek

123>叶卡萨(Oksad)本身

123>yeksad o bist o se

1,123>叶赫扎尔·叶卡萨德·拜斯特本人

1,123>yek hezar o yeksad o bist o se

3,002,001> se milion o do hezar o yek ...

3,002,001>se milion o do hezar o yek ...

我,我是目标c的初学者:)

I,m beginner in objective c :)

我用c编写了它,但我想将其转换为obj_c!我该怎么办?

类似的东西

const char  *yekan[10]={"","yek","do","se","chahar","panj","shesh","haft","hasht","noh"};
char ary[9]={'0','0','0','0','0','0','0','0','0'};

// get a number from user & converting it to string

// user number: 123 > the number in ary:000 000 123)

// '3' => 3

m=(int) ary[8];
m=m-'0';

if (j==3)   { printf(" %s ",yekan[m]);} // yekan[3] = se

output: se

谢谢.

推荐答案

NSNumberFormatter类具有用于将数字转换为单词的内置功能:

NSNumberFormatter class has built-in functionality for conversion numbers to words:

NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
[formatter setNumberStyle: NSNumberFormatterSpellOutStyle];
[formatter setLocale:...]; // Set locale if you want to use something other then the current one
NSString* numberString = [formatter stringFromNumber:[NSNumber numberWithInt: 100]];

这篇关于在目标c中将数字转换为单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 09:34