CultureInfo.NumberFormat CultureInfo.NumberFormat CultureInfo.NumberFormat CultureInfo.NumberFormat Property

Definición

Obtiene o establece un objeto NumberFormatInfo que define el formato de presentación de números, moneda y porcentaje culturalmente apropiado.Gets or sets a NumberFormatInfo that defines the culturally appropriate format of displaying numbers, currency, and percentage.

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

Valor de propiedad

NumberFormatInfo que define el formato de presentación de números, moneda y porcentaje culturalmente apropiado.A NumberFormatInfo that defines the culturally appropriate format of displaying numbers, currency, and percentage.

Excepciones

La propiedad se ha establecido en null.The property is set to null.

Se establece la propiedad NumberFormat o cualquiera de las propiedades NumberFormatInfo, y CultureInfo es de solo lectura.The NumberFormat property or any of the NumberFormatInfo properties is set, and the CultureInfo is read-only.

Ejemplos

En el ejemplo de código siguiente se muestra que cómo CultureInfo.Clone también clona el DateTimeFormatInfo y NumberFormatInfo las instancias asociadas a la CultureInfo.The following code example shows that CultureInfo.Clone also clones the DateTimeFormatInfo and NumberFormatInfo instances associated with the 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
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 'Main 

End Class 'SamplesCultureInfo


' 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

Comentarios

OverridesOverrides

El usuario puede optar por invalidar algunos de los valores asociados con la referencia cultural actual de Windows a través de la parte de opciones de configuración regional y de idioma del Panel de Control.The user might choose to override some of the values associated with the current culture of Windows through the regional and language options portion of Control Panel. Por ejemplo, el usuario podría elegir para mostrar la fecha en un formato diferente o use una divisa distinta a la predeterminada para la referencia cultural.For example, the user might choose to display the date in a different format or to use a currency other than the default for the culture.

Si UseUserOverride es true y la referencia cultural especificada coincide con la referencia cultural actual de Windows, el CultureInfo utiliza las nuevas, incluida la configuración de usuario para las propiedades de la DateTimeFormatInfo instancia devuelta por la DateTimeFormat propiedad, y las propiedades de la NumberFormatInfo instancia devuelta por la NumberFormat propiedad.If UseUserOverride is true and the specified culture matches the current culture of Windows, the CultureInfo uses those overrides, including user settings for the properties of the DateTimeFormatInfo instance returned by the DateTimeFormat property, and the properties of the NumberFormatInfo instance returned by the NumberFormat property. Si la configuración de usuario no es compatible con la referencia cultural asociada con el CultureInfo, por ejemplo, si el calendario seleccionado no es uno de los OptionalCalendars, los resultados de los métodos y los valores de las propiedades no están definidos.If the user settings are incompatible with the culture associated with the CultureInfo, for example, if the selected calendar is not one of the OptionalCalendars, the results of the methods and the values of the properties are undefined.

Los valores de la DateTimeFormat propiedad y el NumberFormat propiedad no se calculan hasta que el usuario tiene acceso a la propiedad.The values of the DateTimeFormat property and the NumberFormat property are not calculated until the user accesses the property. Si el usuario usa el Panel de Control para cambiar la referencia cultural actual a una nueva referencia cultural mientras la aplicación está en ejecución y, a continuación, tiene acceso a la DateTimeFormat o NumberFormat propiedad, la aplicación recupera los valores predeterminados para la nueva referencia cultural.If the user uses the Control Panel to change the current culture to a new culture while the application is running and then accesses the DateTimeFormat or NumberFormat property, the application retrieves the defaults for the new culture. no las invalidaciones de la referencia cultural original.not the overrides for the original culture. Para conservar las invalidaciones de la referencia cultural original, la aplicación debe tener acceso a la DateTimeFormat y NumberFormat propiedades antes de cambiar la referencia cultural actual.To preserve the overrides for the original current culture, the application should access the DateTimeFormat and NumberFormat properties before changing the current culture.

Se aplica a

Consulte también: