Formatting iOS numbers and formatting iOS numbers

Source: Internet
Author: User

Formatting iOS numbers and formatting iOS numbers

// You can also set the format of NSNumber output through NSNumberFormatter. For example, the following code: NSNumberFormatter * formatter = [[NSNumberFormatter alloc] init]; formatter. numberStyle = NSNumberFormatterDecimalStyle; NSString * string = [formatter stringFromNumber: [NSNumber numberWithInt: 123456789]; NSLog (@ "Formatted number string: % @", string ); // The output result is: [1223:403] Formatted number string: 123,456,789 // The NSNumberFormatter class has a property numberStyle, which is an enumeration type, you can set different values to output different numeric formats. This enumeration includes: typedef NS_ENUM (NSUInteger, NSNumberFormatterStyle) {NSNumberFormatterNoStyle = kCFNumberFormatterNoStyle, Signature = signature, Signature = signature, NSNumberFormatterPercentStyle = signature, Signature = delimiter, NSNumberFormatterSpellO UtStyle = kCFNumberFormatterSpellOutStyle}; // The output format of each enumeration is as follows: the output of the third and last entries varies depending on the language regions set by the system. [1243: 403] Formatted number string: 123456789 [1243: 403] Formatted number string: 123,456,789 [1243: 403] Formatted number string: ¥123,456,789.00 [1243: 403] Formatted number string: -539,222,988% [1243: 403] Formatted number string: 1.23456789E8 [1243: 403] Formatted number string: 0.1 billion 23,456,789

Related Article

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.