NumberFormatInfo.PercentDecimalDigits Właściwość

Definicja

Pobiera lub ustawia liczbę miejsc dziesiętnych do użycia w wartościach procentowych.

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

Wartość właściwości

Liczba miejsc dziesiętnych do użycia w wartościach procentowych. Wartość domyślna to InvariantInfo 2.

Wyjątki

Właściwość jest ustawiana na wartość mniejszą niż 0 lub większą niż 99.

Właściwość jest ustawiana, a NumberFormatInfo obiekt jest tylko do odczytu.

Przykłady

W poniższym przykładzie pokazano efekt zmiany PercentDecimalDigits właściwości.

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 %

Uwagi

Właściwość PercentDecimalDigits jest używana z ciągiem formatu standardowego "P" bez specyfikatora dokładności w operacjach formatowania liczbowego. Definiuje domyślną liczbę cyfr ułamkowych wyświetlanych po separatorze dziesiętny. Ta wartość jest zastępowana, jeśli jest używany specyfikator dokładności. Aby uzyskać więcej informacji, zobacz Standardowe ciągi formatu liczbowego.

Dotyczy

Zobacz też