How to customize the number format string in C # ToString ###,###,###,# #0

Source: Internet
Author: User
Tags tostring

###,###,###,# #0

#是如果有数字的话就显示, there is no number of words is empty, 0 is if there is a number of words on display, no number is displayed as 0.

EG:

public string getformatestring (int Precision, double number)  
        {  
            string text = "###,###,###,# #0.";  
            for (int i = 0; i < Precision i++)  
            {  
                text = "0";  
            }  
            return number.tostring (text);  
        

In the example above, the string that you say you want to format is output according to the precision (Precision), quantity (number) passed in by the function, where the for loop is the number of zeros after stitching the decimal point, which is zero placeholder.

This paper url:http://www.bianceng.cn/programming/csharp/201410/45584.htm

Debugging through breakpoints, visible, as shown in the following figure:

The parameters passed in at the time of the call are:

MessageBox.Show (getformatestring (10,2.0));

The output results are:

For content with custom numeric format strings, you can view the MSDN Web site: Click to open the link

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.