C # Custom numeric format string ToString ###,###,###,# #0

Source: Internet
Author: User
###,###,###,# #0

#是如果有数字的话就显示, no number is empty, 0 is displayed if there is a number, 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, according to the function's incoming precision (Precision), quantity (number), you say that you need to format the string, where the function of the For loop is to stitch the number of zeros after the decimal point, zero placeholder.

Debugging through breakpoints, visible, such as:

The arguments passed in at the time of invocation are:


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

The output is:


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

The above is the C # custom numeric format string ToString ###,###,###,# #0的内容, for more information please follow topic.alibabacloud.com (www.php.cn)!

  • 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.