Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.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
Iphone 使用货币时如何将小数点设置为0_Iphone_Decimal_Currency_Nsnumberformatter - Fatal编程技术网

Iphone 使用货币时如何将小数点设置为0

Iphone 使用货币时如何将小数点设置为0,iphone,decimal,currency,nsnumberformatter,Iphone,Decimal,Currency,Nsnumberformatter,在我的应用程序中,我处理大数字(货币),并使用nsnumberformatter对其进行格式化。但是,目前,小数位数是根据区域设置的。由于涉及大数字,我不希望以任何货币显示小数位数。如何在nsnumberformatter货币样式中将小数点设置为零 使用的代码 NSDecimalNumber *someAmount = [NSDecimalNumber decimalNumberWithString:unformattedString]; NSNumberFormatter *curre

在我的应用程序中,我处理大数字(货币),并使用nsnumberformatter对其进行格式化。但是,目前,小数位数是根据区域设置的。由于涉及大数字,我不希望以任何货币显示小数位数。如何在nsnumberformatter货币样式中将小数点设置为零

使用的代码

NSDecimalNumber *someAmount = [NSDecimalNumber decimalNumberWithString:unformattedString];
    NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease];
    [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
    [currencyFormatter setLocale:locale];
    NSString *str=[NSString stringWithFormat:@"%.0f",someAmount];
    //NSString *str=[currencyFormatter stringFromNumber:someAmount];

使用以下代码删除数字格式化程序中的小数位数:

[currencyFormatter setMaximumFractionDigits:0];
使用上述代码的完整代码:

NSDecimalNumber *someAmount = [NSDecimalNumber decimalNumberWithString:unformattedString];
NSNumberFormatter *currencyFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyFormatter setLocale:locale];
[currencyFormatter setMaximumFractionDigits:0];
NSString *str=[currencyFormatter stringFromNumber:someAmount];

是否可以查看正在格式化数字的代码。我正在使用已注释的代码,现在我根据建议进行了更改。我刚刚编辑了我的答案,您需要将数字格式化程序上的MaximumFractionDigits设置为0。仅当价格为3,00,即所有小数都为零时,是否可以删除小数?