NumberFormatInfo.PercentDecimalDigits Vlastnost

Definice

Získá nebo nastaví počet desetinných míst pro použití v procentuálních hodnotách.

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

Hodnota vlastnosti

Počet desetinných míst, která se mají použít v procentuálních hodnotách. Výchozí hodnota pro InvariantInfo je 2.

Výjimky

Vlastnost je nastavena na hodnotu, která je menší než 0 nebo větší než 99.

Vlastnost se nastavuje a NumberFormatInfo objekt je jen pro čtení.

Příklady

Následující příklad ukazuje účinek změny PercentDecimalDigits vlastnosti .

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 %

Poznámky

Vlastnost se PercentDecimalDigits používá se standardním formátovacím řetězcem "P" bez specifikátoru přesnosti v operacích číselného formátování. Definuje výchozí počet desetinných míst, které se zobrazí za oddělovačem desetinných míst. Tato hodnota je přepsána, pokud je použit specifikátor přesnosti. Další informace najdete v tématu Řetězce standardního číselného formátu.

Platí pro

Viz také