A shortcut to convert a number to a string

Source: Internet
Author: User

1. A shortcut to convert a number to a string

2, please completely discard the float type, using CGFloat or double,float is not accurate enough.

BOOL B1 =YES; BOOL B2=NO; Nsinteger T1=100000; intt2 =200000; floatT3 =300000.02; CGFloat T33=300000.02; DoubleT4 =400000.0000003; NSNumber*NUM1 = @ (123); NSNumber*num2 = @ (123.00005); NSLog (@"BOOL b1:%@", [@ (B1) stringvalue]);//BOOL b1:1NSLog (@"BOOL b2:%@", [@ (B2) stringvalue]);//BOOL b2:0NSLog (@"Nsinteger t1:%@", [@ (T1) stringvalue]);//Nsinteger t1:100000NSLog (@"int t2:%@", [@ (T2) stringvalue]);//int t2:200000NSLog (@"float t3:%@", [@ (T3) stringvalue]);//Float t3:300000 # #失真NSLog (@"float t3:%f", T3);//Float t3:300000.031250 # #失真NSLog (@"float t3:%.2f", T3);//Float t3:300000.03 # #失真NSLog (@"float t33:%@", [@ (T33) stringvalue]);//float t33:300000.02NSLog (@"float t33:%f", T33);//float t33:300000.020000NSLog (@"Double t4:%@", [@ (T4) stringvalue]);//Double t4:400000.0000003NSLog (@"NSNumber *num1:%@", [Num1 stringvalue]);//NSNumber *num1:123NSLog (@"NSNumber *num2:%@", [num2 stringvalue]);//NSNumber *num2:123.00005

A shortcut to convert a number to a string

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.