0

Jon Skeet said that "" and String.Empty are equivalent due to string interning. In looking at MSDN for ICustomFormatter there is a line in the Format method

// Handle null or empty format string, string with precision specifier.
string thisFmt = String.Empty;

At first I thought they might be adding an empty string in order to avoid dealing with nulls in later logic. But this doesn't explain what they mean by "precision specifier".

What is a "precision specifier"?

Community
  • 1
  • 1
P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348

3 Answers3

3

When formatting strings to number types a precision specifier can be supplied in the format string as in the following examples:

 int quantity = 1500;
 float price = 1.50F;
 float discount = 0.05F;

 Console.WriteLine(quantity.ToString("n0"));        // Outputs "1,500"
 Console.WriteLine(price.ToString("c"));            // Outputs "£1.50"
 Console.WriteLine(discount.ToString("p1"));        // Outputs "5.0 %"

In the case of the fixed point and percentage specifier a number is included. This is the precision specifier and is used to modify the format.

mreyeros
  • 4,359
  • 20
  • 24
2

From here:

The precision specifier ranges from 0 to 99 and controls the number of significant digits or zeros to the right of a decimal.

Garrett Vlieger
  • 9,354
  • 4
  • 32
  • 44
1

It probably means that later, this variable will contain a format string, which includes a precision specifier. I.e., if a double value is formatted, then you can specify how many digits to the right of the decimal point will be displayed. It is not linked to string internals.

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188