有没有更容易的方式来显示$ currency格式?(作为特殊的逗号)我可以将RE与Objective C代码集成吗? [英] IS there any easier way to show $ currency format?(As specially commas) Can I integrate RE with Objective C code?

查看:98
本文介绍了有没有更容易的方式来显示$ currency格式?(作为特殊的逗号)我可以将RE与Objective C代码集成吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用X代码4。



并使用美元货币计算器。



我的目标是



$ 1,234


$ b显示正确格式的数字?



$ b

$ 12,100



$ 1,23,123



我不想通过追加和字符串。



有更简单的方法,所以我可以整合任何RE或
任何ruby或Python。



请显示我更简单的方式,而不是长期编程。

解决方案

NSNumberFormatter 允许您格式化货币。示例取自 [iOS开发人员:提示];

  //创建formatter 
NSNumberFormatter * formatter = [[NSNumberFormatter alloc] init];
// --------------------------------------------
//将格式设置为货币,输出到控制台
// ------------------------------ --------------
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSString * formattedOutput = [formatter stringFromNumber:[NSNumber numberWithInt:1234]];
NSLog(@输出为货币:%@,formattedOutput);

// ---------------------------------------- ----
//将本地和输出更改为货币
// ---------------------------- ----------------
NSLocale * locale = [[NSLocale alloc] initWithLocaleIdentifier:@it_IT];
[formatter setLocale:locale];
formattedOutput = [formatter stringFromNumber:[NSNumber numberWithInt:1234]];
NSLog(@输出为货币 - 语言环境it_IT:%@,formattedOutput);

[locale release];
[formatter release];


I using X code 4.

And Making an US Currency Calculator.

My Aim is to display the numbers in proper format?

Like

$ 1,234

$12,100

$1,23,123

I dont want do this by appending , and string stuff.

Is there any easier way so that I can integrate any RE or any ruby or Python. Which will help me to make currency format.

Please show me easier way rather than long programming.

解决方案

The NSNumberFormatter allows you to format currency. Example taken from [iOS developer:tips];

// Create formatter
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];  
//--------------------------------------------
// Format style as currency, output to console
//--------------------------------------------
[formatter setNumberStyle:NSNumberFormatterCurrencyStyle];
NSString *formattedOutput = [formatter stringFromNumber:[NSNumber numberWithInt:1234]];
NSLog(@"Output as currency: %@", formattedOutput);

//--------------------------------------------
// Change local and output as currency
//--------------------------------------------
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"it_IT"];
[formatter setLocale:locale];
formattedOutput = [formatter stringFromNumber:[NSNumber numberWithInt:1234]];
NSLog(@"Output as currency - locale it_IT: %@", formattedOutput);

[locale release];
[formatter release];

这篇关于有没有更容易的方式来显示$ currency格式?(作为特殊的逗号)我可以将RE与Objective C代码集成吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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