本文介绍了使用NSNumberFormatter格式化输出UILabel中的货币的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
NSNumberFormatter * fmt;
NSNumber * n;
fmt = [ [ NSNumberFormatter alloc ] init ];
n = [ NSNumber numberWithFloat: 10 ];
[ fmt setFormatterBehavior: NSNumberFormatterBehavior10_4 ];
[ fmt setCurrencySymbol: @"$" ];
[ fmt setNumberStyle: NSNumberFormatterCurrencyStyle ];
// NSLog( @"%@", [ fmt stringFromNumber: n ];
[ fmt release ]
-(IBAction)buttonPressed1:(id)sender
{
double currency = [Amount1.text doubleValue] + [Amount2.text doubleValue];
SumCurrency.text = [NSString stringWithFormat:@"%0.0f", currency];
}
如何将SumCurrency.text设置为1,999而不是1999
How do I get the SumCurrency.text formated as 1,999 instead of 1999
请帮助..我是Objective-C的新手,但是我的项目几乎是95%的界面生成器.
Please help .. I am new to Objective - C , but my project is almost 95 % on interface builder .
我只需要上述代码的帮助即可实现..请为此付出很多努力.
I just need help with above code to implement .. Please I am struggling a lot with this .
关于,新手.
推荐答案
我得到了答案..但对于任何将来的推荐人
I got the answer .. But for anyone's future refernce
-(IBAction)buttonPressed1:(id)sender
{
double currency = [Amount1.text doubleValue] + [Amount2.text doubleValue];
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
NSString *numberAsString = [numberFormatter stringFromNumber:[NSNumber numberWithInt:currency]];
SumCurrency.text = [NSString stringWithFormat:@"Converted:%@",numberAsString];
}
这篇关于使用NSNumberFormatter格式化输出UILabel中的货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!