Sdílet prostřednictvím


NumberFormatInfo.NumberDecimalDigits Vlastnost

Definice

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

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

Hodnota vlastnosti

Počet desetinných míst, která se mají použít v číselných hodnotách. 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 NumberDecimalDigits 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).
      Int64 myInt = -1234;
      Console.WriteLine( myInt.ToString( "N", nfi ) );

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


/*
This code produces the following output.

-1,234.00
-1,234.0000
*/
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 Int64 = - 1234
      Console.WriteLine(myInt.ToString("N", nfi))

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

   End Sub

End Class


'This code produces the following output.
'
'-1,234.00
'-1,234.0000

Poznámky

Vlastnost NumberDecimalDigits se používá s řetězci standardního formátu "F" a "N" 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é