Find out number of fraction digits in currency in iOS
I use NSNumberFormatter to format currencies in a localized way, and it works fine. But I want to override this and give the user the option to override the number of digits after the decimal separator.
How can I find out the number of digits the NSNumberFormatter will use for a certain currency? I have looked in the NSLocale object, but none of the keys tell me this.
NSString * const NSLocaleIdentifier;
NSString * const NSLocaleLanguageCode;
NSString * const NSLocaleCountryCode;
NSString * const NSLocaleScriptCode;
NSString * const NSLocaleVariantCode;
NSString * const NSLocaleExemplarCharacterSet;
NSString * const NSLocaleCalendar;
NSString * const NSLocaleCollationIdentifier;
NSString * const NSLocaleUsesMetricSystem;
NSString * const NSLocaleMeasurementSystem;
NSString * const NSLocaleDecimalSeparator;
NSString * const NSLocaleGroupingSeparator;
NSString * const NSLocaleCurrencySymbol;
NSString * const NSLocaleCurrencyCode;
NSString * const NSLocaleCollatorIdentifier;
NSString * const NSLocaleQuotationBeginDelimiterKey;
NSString * const NSLocaleQuotationEndDelimiterKey;
NSString * const NSLocaleAlternateQuotationBeginDelimiterKey;
NSString * const NSLocaleAlternateQuotationEndDelimiterKey;
How can I find out the correct number of decimals for a currency like the NSNumberFormatter seems to know?
Create an NSNumberFormatter instance and set the currency code with the desired currency. You can then query the property maximumFractionDigits on the currency formatter.
链接地址: http://www.djcxy.com/p/67356.html上一篇: 检查NSString是否包含有效的数字,但是是本地化的
下一篇: 在iOS中查找货币的小数位数