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 namespace System;
using namespace System::Globalization;
int main()
{
   
   // Gets a NumberFormatInfo associated with the en-US culture.
   CultureInfo^ MyCI = gcnew CultureInfo( "en-US",false );
   NumberFormatInfo^ nfi = MyCI->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 %
*/
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" без спецификатора точности в операциях числового форматирования. Он определяет число дробных цифр по умолчанию, которые отображаются после десятичного разделителя. Это значение переопределяется, если используется описатель точности. Дополнительные сведения см. в статье Строки стандартных числовых форматов.

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

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