C# custom number format string ToString ###,###,###,##0

黄舟
Release: 2017-02-21 11:06:05
Original
1573 people have browsed it

   

,

,
,##0

      # means if there are numbers, it will be displayed, if there are no numbers, it will be empty; 0 means if there are digits, it will be displayed, there will be no numbers If so, it 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);
        }
Copy after login

## In the above example, according to the precision passed in by the function (Precision ), quantity (Number) to output the string you said needs the format. The function of the for loop is to splice the number of zeros after the decimal point and occupy the zero place.

Through breakpoint debugging, it can be seen, as shown below:

## The parameters passed in when calling are:


MessageBox.Show(GetFormateString(10,2.0));
Copy after login
The output result is:



For content related to the custom number format string, you can view the MSDN website: click to open Link

The above is the content of C# custom number format string ToString

,
,
,##0. For more related content, please pay attention to the PHP Chinese website (www. php.cn)!


############
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!