What is ToString(“N0”) format?

2019-02-01 04:16发布

This code is from Charles Pettzold's "Programming Windows Sixth Edition" book:

public object Convert(object value, Type targetType, object parameter, string language) 
{ 
    return ((double)value).ToString("N0"); 
}

ToString("N0") is supposed to print the value with comma separators and no decimal points. I cannot find the reference to appropriate ToString overload and "N0" format in the documentation. Please point me to the right place in .NET documentation.

4条回答
Luminary・发光体
2楼-- · 2019-02-01 04:35

You can find the list of formats here (in the Double.ToString()-MSDN-Article) as comments in the example section.

查看更多
该账号已被封号
3楼-- · 2019-02-01 04:37

Here is a good start maybe

Double.ToString()

Have a look in the examples for a number of different formating options Double.ToString(string)

查看更多
祖国的老花朵
4楼-- · 2019-02-01 04:45

This is where the documentation is:

http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx

The numeric ("N") format specifier converts a number to a string of the form "-d,ffffd,ffffd.ffffd…", where "-" indicates a negative number symbol if required, "d" indicates a digit (0-9) ...

And this is where they talk about the default (2):

http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.numberdecimaldigits.aspx

      // Displays a negative value with the default number of decimal digits (2).
      Int64 myInt = -1234;
      Console.WriteLine( myInt.ToString( "N", nfi ) );
查看更多
做自己的国王
5楼-- · 2019-02-01 04:47

Checkout the following article on MSDN about examples of the N format. This is also covered in the Standard Numeric Format Strings article.

Relevant excerpt:

//       Formatting of 1054.32179:
//          N:                     1,054.32 
//          N0:                    1,054 
//          N1:                    1,054.3 
//          N2:                    1,054.32 
//          N3:                    1,054.322 
查看更多
登录 后发表回答