"IOS" Nsnumberformatter

Source: Internet
Author: User

Introduced

Nsnumberformatter should be able to meet your general needs in the form of data, worth knowing.

    NSNumber *NUM1 = [NSNumber numberwithdouble:1234567.8369];==================== class Method ====================Rounded integersNSString *NUMBERNOSTYLESTR = [Nsnumberformatter localizedstringfromnumber:num1 NumberStyle:Nsnumberformatternostyle];Decimal formNSString *NUMBERDECIMALSTYLESTR = [Nsnumberformatter localizedstringfromnumber:num1 NumberStyle:Nsnumberformatterdecimalstyle];Currency form-LocalizationNSString *NUMBERCURRENCYSTYLESTR = [Nsnumberformatter localizedstringfromnumber:num1 NumberStyle:Nsnumberformattercurrencystyle];Percent formNSString *NUMBERPERCENTSTYLESTR = [Nsnumberformatter localizedstringfromnumber:num1 NumberStyle:Nsnumberformatterpercentstyle];Scientific countingNSString *NUMBERSCIENTIFICSTYLESTR = [Nsnumberformatter localizedstringfromnumber:num1 NumberStyle:Nsnumberformatterscientificstyle];Read aloud form-localizationNSString *NUMBERSPELLOUTSTYLESTR = [Nsnumberformatter localizedstringfromnumber:num1 NumberStyle:Nsnumberformatterspelloutstyle];Ordinal form-LocalizationNSString *NUMBERORDINALSTYLESTR = [Nsnumberformatter localizedstringfromnumber:num1 NumberStyle:Nsnumberformatterordinalstyle];Currency form ISO--localizationNSString *NUMBERCURRENCYISOSTYLESTR = [Nsnumberformatter localizedstringfromnumber:num1 NumberStyle:Nsnumberformattercurrencyisocodestyle];Currency form-LocalizationNSString *NUMBERCURRENCYPLURALSTYLESTR = [Nsnumberformatter localizedstringfromnumber:num1 NumberStyle:Nsnumberformattercurrencypluralstyle];Accounting Counting-localizationNSString *NUMBERCURRENCYACCOUNTINGSTYLESTR = [Nsnumberformatter localizedstringfromnumber:num1 NumberStyle:Nsnumberformattercurrencyaccountingstyle];NSLog (@ "No Style =%@", numbernostylestr);No Style = 1234568NSLog (@ "Decimal Style =%@", numberdecimalstylestr);Decimal Style = 1,234,567.837NSLog (@ "Currency Style =%@", numbercurrencystylestr);Currency Style = $1,234,567.84NSLog (@ "Percent Style =%@", numberpercentstylestr);Percent Style = 123,456,784%NSLog (@ "Scientific Style =%@", numberscientificstylestr);Scientific Style = 1.2345678369E6Spell out Style = One million, hundred thirty-four thousand five hundred Sixty-seven Point eight three six nineNSLog (@ "Spell out Style =%@", numberspelloutstylestr);NSLog (@ "Ordinal Style =%@", numberordinalstylestr);Ordinal Style = 1,234,568thNSLog (@ "Currency ISO Style =%@", numbercurrencyisostylestr);Currency ISO Style = usd1,234,567.84NSLog (@ "Currency plural Style =%@", numbercurrencypluralstylestr);Currency plural Style = 1,234,567.84 US dollarsNSLog (@ "Currency Accounting Style =%@", numbercurrencyaccountingstylestr);Currency Accounting Style = $1,234,567.84==================== Custom ====================Nsnumberformatter *numberformatter = [Nsnumberformatter new]; Numberformatter. NumberStyle =Nsnumberformatterdecimalstyle;Format width numberformatter. Formatwidth =15;Shim Numberformatter. Paddingcharacter =@"?";Fill position Numberformatter. paddingposition = kCfnumberformatterpadbeforesuffix; Numberformatter. Positivesuffix =@ "Yuan";NSLog (@ "%@", [Numberformatter numberfromstring:@ "10000000 yuan"]);10000000Zoom factor, you can scale a number to a specified scale, and then add a suffix to it, such as passing in a 3000, you want to represent 3,000, you need to use this propertyPrevent the subsequent tests from being affected, so note offNumberformatter.multiplier = @1000;NSLog (@ "%@ thousand", [Numberformatter numberfromstring:@ "1000"]); 1000Numberformatter.multiplier = @0.001;Numberformatter.positivesuffix = @ "thousand";NSLog (@ "%@", [Numberformatter stringfromnumber:@10000]); 10,000Mechanism ambiguous, minus, plus signNumberformatter.negativeformat = @ "^";Numberformatter.positiveformat = @ "~0";Looks like nothing to use Numberformatter.. Allowsfloats =NO; Numberformatter. Alwaysshowsdecimalseparator =NO; Numberformatter. Maximum = @1000; Numberformatter. Minimum = @100;Decimal Style Numberformatter. DecimalSeparator =@".";Zero-style Numberformatter. Zerosymbol =@"-";Prefix and suffix numberformatter. Positiveprefix =@"!"; Numberformatter. Positivesuffix =@ "Yuan"; Numberformatter. Negativeprefix =@"@"; Numberformatter. Negativesuffix =@ "Loss";The specified symbol is consistent with what we described in the previous class methodNSLog (@ "Currency code%@", Numberformatter. CurrencyCode);Currency Code USDNSLog (@ "Currency symbol%@", Numberformatter. CurrencySymbol);Currency symbol $NSLog (@ "International currency symbol%@", Numberformatter. Internationalcurrencysymbol);International currency symbol USDNSLog (@ "percent sign%@", Numberformatter. Percentsymbol);Percent Sign%NSLog (@ "Chiphi symbol%@", Numberformatter. Permillsymbol);Thousand semicolon symbol‰NSLog (@ "Minus sign%@", Numberformatter. minussign);Minus sign-NSLog (@ "plus sign%@", Numberformatter. plussign);PLUS sign +NSLog (@ "exponential symbol%@", Numberformatter. Exponentsymbol);Exponential sign EInteger maximum number of digits Numberformatter. maximumintegerdigits =10;Integer minimum number of digits Numberformatter. minimumintegerdigits =2;Maximum number of decimal digits Numberformatter. maximumfractiondigits =3;Minimum number of decimal digits Numberformatter. minimumfractiondigits =1;Size Numberformatter for digital segmentation. groupingsize =4;In addition to the size of the groupingsize decision, the size of other digital bits Numberformatter. secondarygroupingsize =2;Maximum number of valid digits Numberformatter. maximumsignificantdigits =12; ///minimum number of valid digits Numberformatter. minimumsignificantdigits = 3; NSLog (@ "positive%@, Negative%@", [Numberformatter stringfromnumber:@ (+12135230.2346)],[numberformatter stringfromnumber:@ (-12135231.2346)]); //Positive!12,13,5230.2346 yuan, negative @12,13,5231.2346 loss NSLog (@ "0 =%@", [Numberformatter stringfromnumber:@ (0) ]); //0 =- //rounded value, such as 10 for the carry value, then 156 is carry 160,154 carry for the Numberformatter. roundingincrement = @10; //Rounding Method                



Wen/Liu Dahuan (Jane book author)
Original link: http://www.jianshu.com/p/817029422a72
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".

"IOS" Nsnumberformatter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.