NumberFormatInfo.PercentDecimalDigits Свойство

Определение

Возвращает или задает число десятичных разрядов, используемых в процентах значений.

public:
 property int PercentDecimalDigits { int get(); void set(int value); };
public int PercentDecimalDigits { get; set; }
member this.PercentDecimalDigits : int with get, set
Public Property PercentDecimalDigits As Integer

Значение свойства

Количество десятичных разрядов, используемых в процентах значений. Значение по умолчанию InvariantInfo — 2.

Исключения

Свойство задается значением, которое меньше 0 или больше 99.

Свойство задано, и NumberFormatInfo объект доступен только для чтения.

Примеры

В следующем примере показано влияние изменения PercentDecimalDigits свойства.

using System;
using System.Globalization;

class NumberFormatInfoSample {

   public static void Main() {

      // Gets a NumberFormatInfo associated with the en-US culture.
      NumberFormatInfo nfi = new CultureInfo( "en-US", false ).NumberFormat;

      // Displays a negative value with the default number of decimal digits (2).
      Double myInt = 0.1234;
      Console.WriteLine( myInt.ToString( "P", nfi ) );

      // Displays the same value with four decimal digits.
      nfi.PercentDecimalDigits = 4;
      Console.WriteLine( myInt.ToString( "P", nfi ) );
   }
}


/*
This code produces the following output.

12.34 %
12.3400 %
*/
Imports System.Globalization

Class NumberFormatInfoSample

   Public Shared Sub Main()

      ' Gets a NumberFormatInfo associated with the en-US culture.
      Dim nfi As NumberFormatInfo = New CultureInfo("en-US", False).NumberFormat

      ' Displays a negative value with the default number of decimal digits (2).
      Dim myInt As [Double] = 0.1234
      Console.WriteLine(myInt.ToString("P", nfi))

      ' Displays the same value with four decimal digits.
      nfi.PercentDecimalDigits = 4
      Console.WriteLine(myInt.ToString("P", nfi))

   End Sub

End Class


'This code produces the following output.
'
'12.34 %
'12.3400 %

Комментарии

Свойство PercentDecimalDigits используется со строкой стандартного формата P без описателя точности в числовых операциях форматирования. Он определяет число дробных цифр по умолчанию, которое отображается после десятичного разделителя. Это значение переопределяется, если используется описатель точности. Дополнительные сведения см. в разделе "Строки стандартного числового формата".

Применяется к

См. также раздел