Home  >  Article  >  Backend Development  >  C# custom number format string ToString ###,###,###,##0

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

黄舟
黄舟Original
2017-02-21 11:06:051536browse

   

,

,
,##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);
        }

## 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));

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)!


############
Statement:
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