CultureInfo.NumberFormat Proprietà

Definizione

Ottiene o imposta un oggetto NumberFormatInfo che definisce il formato culturalmente appropriato per la visualizzazione di numeri, valute e percentuali.

public:
 virtual property System::Globalization::NumberFormatInfo ^ NumberFormat { System::Globalization::NumberFormatInfo ^ get(); void set(System::Globalization::NumberFormatInfo ^ value); };
public virtual System.Globalization.NumberFormatInfo NumberFormat { get; set; }
member this.NumberFormat : System.Globalization.NumberFormatInfo with get, set
Public Overridable Property NumberFormat As NumberFormatInfo

Valore della proprietà

Oggetto NumberFormatInfo che definisce il formato culturalmente appropriato per la visualizzazione di numeri, valute e percentuali.

Eccezioni

La proprietà è impostata su Null.

La proprietà NumberFormat o una qualsiasi delle proprietà NumberFormatInfo vengono impostate e l'interfaccia CultureInfo è di sola lettura.

Esempio

Nell'esempio di codice seguente viene illustrato che CultureInfo.Clone clona anche le DateTimeFormatInfo istanze e NumberFormatInfo associate a CultureInfo.

using namespace System;
using namespace System::Globalization;
int main()
{
   
   // Creates and initializes a CultureInfo.
   CultureInfo^ myCI = gcnew CultureInfo( "en-US",false );
   
   // Clones myCI and modifies the DTFI and NFI instances associated with the clone.
   CultureInfo^ myCIclone = dynamic_cast<CultureInfo^>(myCI->Clone());
   myCIclone->DateTimeFormat->AMDesignator = "a.m.";
   myCIclone->DateTimeFormat->DateSeparator = "-";
   myCIclone->NumberFormat->CurrencySymbol = "USD";
   myCIclone->NumberFormat->NumberDecimalDigits = 4;
   
   // Displays the properties of the DTFI and NFI instances associated with the original and with the clone. 
   Console::WriteLine( "DTFI/NFI PROPERTY\tORIGINAL\tMODIFIED CLONE" );
   Console::WriteLine( "DTFI.AMDesignator\t{0}\t\t{1}", myCI->DateTimeFormat->AMDesignator, myCIclone->DateTimeFormat->AMDesignator );
   Console::WriteLine( "DTFI.DateSeparator\t{0}\t\t{1}", myCI->DateTimeFormat->DateSeparator, myCIclone->DateTimeFormat->DateSeparator );
   Console::WriteLine( "NFI.CurrencySymbol\t{0}\t\t{1}", myCI->NumberFormat->CurrencySymbol, myCIclone->NumberFormat->CurrencySymbol );
   Console::WriteLine( "NFI.NumberDecimalDigits\t{0}\t\t{1}", myCI->NumberFormat->NumberDecimalDigits, myCIclone->NumberFormat->NumberDecimalDigits );
}

/*
This code produces the following output.

DTFI/NFI PROPERTY       ORIGINAL        MODIFIED CLONE
DTFI.AMDesignator       AM              a.m.
DTFI.DateSeparator      /               -
NFI.CurrencySymbol      $               USD
NFI.NumberDecimalDigits 2               4
*/
using System;
using System.Globalization;

public class SamplesCultureInfo  {

   public static void Main()  {

      // Creates and initializes a CultureInfo.
      CultureInfo myCI = new CultureInfo("en-US", false);

      // Clones myCI and modifies the DTFI and NFI instances associated with the clone.
      CultureInfo myCIclone = (CultureInfo) myCI.Clone();
      myCIclone.DateTimeFormat.AMDesignator = "a.m.";
      myCIclone.DateTimeFormat.DateSeparator = "-";
      myCIclone.NumberFormat.CurrencySymbol = "USD";
      myCIclone.NumberFormat.NumberDecimalDigits = 4;

      // Displays the properties of the DTFI and NFI instances associated with the original and with the clone.
      Console.WriteLine( "DTFI/NFI PROPERTY\tORIGINAL\tMODIFIED CLONE" );
      Console.WriteLine( "DTFI.AMDesignator\t{0}\t\t{1}", myCI.DateTimeFormat.AMDesignator, myCIclone.DateTimeFormat.AMDesignator );
      Console.WriteLine( "DTFI.DateSeparator\t{0}\t\t{1}", myCI.DateTimeFormat.DateSeparator, myCIclone.DateTimeFormat.DateSeparator );
      Console.WriteLine( "NFI.CurrencySymbol\t{0}\t\t{1}", myCI.NumberFormat.CurrencySymbol, myCIclone.NumberFormat.CurrencySymbol );
      Console.WriteLine( "NFI.NumberDecimalDigits\t{0}\t\t{1}", myCI.NumberFormat.NumberDecimalDigits, myCIclone.NumberFormat.NumberDecimalDigits );
   }
}

/*
This code produces the following output.

DTFI/NFI PROPERTY       ORIGINAL        MODIFIED CLONE
DTFI.AMDesignator       AM              a.m.
DTFI.DateSeparator      /               -
NFI.CurrencySymbol      $               USD
NFI.NumberDecimalDigits 2               4

*/
Imports System.Globalization


Public Class SamplesCultureInfo
   
   Public Shared Sub Main()
      
      ' Creates and initializes a CultureInfo.
      Dim myCI As New CultureInfo("en-US", False)
      
      ' Clones myCI and modifies the DTFI and NFI instances associated with the clone.
      Dim myCIclone As CultureInfo = CType(myCI.Clone(), CultureInfo)
      myCIclone.DateTimeFormat.AMDesignator = "a.m."
      myCIclone.DateTimeFormat.DateSeparator = "-"
      myCIclone.NumberFormat.CurrencySymbol = "USD"
      myCIclone.NumberFormat.NumberDecimalDigits = 4
      
      ' Displays the properties of the DTFI and NFI instances associated with the original and with the clone. 
      Console.WriteLine("DTFI/NFI PROPERTY" + ControlChars.Tab + "ORIGINAL" + ControlChars.Tab + "MODIFIED CLONE")
      Console.WriteLine("DTFI.AMDesignator" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.DateTimeFormat.AMDesignator, myCIclone.DateTimeFormat.AMDesignator)
      Console.WriteLine("DTFI.DateSeparator" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.DateTimeFormat.DateSeparator, myCIclone.DateTimeFormat.DateSeparator)
      Console.WriteLine("NFI.CurrencySymbol" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.NumberFormat.CurrencySymbol, myCIclone.NumberFormat.CurrencySymbol)
      Console.WriteLine("NFI.NumberDecimalDigits" + ControlChars.Tab + "{0}" + ControlChars.Tab + ControlChars.Tab + "{1}", myCI.NumberFormat.NumberDecimalDigits, myCIclone.NumberFormat.NumberDecimalDigits)

   End Sub

End Class


' This code produces the following output.
'
' DTFI/NFI PROPERTY       ORIGINAL        MODIFIED CLONE
' DTFI.AMDesignator       AM              a.m.
' DTFI.DateSeparator      /               -
' NFI.CurrencySymbol      $               USD
' NFI.NumberDecimalDigits 2               4

Commenti

È possibile scegliere di eseguire l'override di alcuni dei valori associati alle impostazioni cultura correnti di Windows tramite la parte delle opzioni internazionali e della lingua di Pannello di controllo. Ad esempio, l'utente potrebbe scegliere di visualizzare la data in un formato diverso o di usare una valuta diversa da quella predefinita per le impostazioni cultura.

Se UseUserOverride è true e le impostazioni cultura specificate corrispondono alle impostazioni cultura correnti di Windows, CultureInfo vengono utilizzate le sostituzioni, incluse le impostazioni utente per le proprietà dell'istanza DateTimeFormatInfo restituita dalla DateTimeFormat proprietà e le proprietà dell'istanza NumberFormatInfo restituita dalla NumberFormat proprietà . Se le impostazioni utente non sono compatibili con le impostazioni cultura associate a CultureInfo, ad esempio, se il calendario selezionato non è uno di OptionalCalendars, i risultati dei metodi e i valori delle proprietà non sono definiti.

I valori della DateTimeFormat proprietà e della NumberFormat proprietà non vengono calcolati finché l'utente non accede alla proprietà . Se l'utente usa il Pannello di controllo per modificare le impostazioni cultura correnti in una nuova lingua mentre l'applicazione è in esecuzione e quindi accede alla DateTimeFormat proprietà oNumberFormat, l'applicazione recupera le impostazioni predefinite per le nuove impostazioni cultura. non le sostituzioni per le impostazioni cultura originali. Per mantenere gli override per le impostazioni cultura correnti originali, l'applicazione deve accedere alle DateTimeFormat proprietà e NumberFormat prima di modificare le impostazioni cultura correnti.

Si applica a

Vedi anche