NumberFormatInfo.PercentDecimalDigits Vlastnost

Definice

Získá nebo nastaví počet desetinných míst, která se mají použít v procentech hodnot.

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 procentech hodnot. Výchozí hodnota je InvariantInfo 2.

Výjimky

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

Vlastnost je nastavena a NumberFormatInfo objekt je jen pro čtení.

Příklady

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

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 PercentDecimalDigits se 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 číslic, které se zobrazí za oddělovačem desetinných míst. Tato hodnota se přepíše, pokud se použije specifikátor přesnosti. Další informace naleznete v tématu Standardní číselné formátovací řetězce.

Platí pro

Viz také