NumberFormatInfo.CurrentInfo Property

Definition

Gets a read-only NumberFormatInfo that formats values based on the current culture.

public static System.Globalization.NumberFormatInfo CurrentInfo { get; }

Property Value

A read-only NumberFormatInfo based on the culture of the current thread.

Examples

The following example shows that the objects returned by the CurrentInfo and CultureInfo.CurrentCulture.NumberFormat properties are identical. It then uses reflection to display the property values of the NumberFormatInfo object returned by the CurrentInfo property on a system whose current culture is en-US.

using System;
using System.Collections;
using System.Globalization;
using System.Reflection;

public class Example : IComparer
{
   public static void Main()
   {
      NumberFormatInfo nfi1 = NumberFormatInfo.CurrentInfo;
      NumberFormatInfo nfi2 = CultureInfo.CurrentCulture.NumberFormat;
      Console.WriteLine("Objects equal: {0}", nfi1.Equals(nfi2));
      Console.WriteLine("Equal references: {0}\n", Object.ReferenceEquals(nfi1, nfi2));

      PropertyInfo[] props = nfi1.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
      Array.Sort(props, new Example());
      Console.WriteLine("Properties of NumberFormat.CurrentInfo object:");
      foreach (var prop in props) {
         if (prop.PropertyType.IsArray) {
            Array arr = prop.GetValue(nfi1) as Array;
            Console.Write(String.Format("   {0}: ", prop.Name) + "{ ");
            int ctr = 0;
            foreach (var item in arr) {
               Console.Write("{0}{1}", item, ctr == arr.Length - 1 ?" }" : ", ");
               ctr++;
            }
            Console.WriteLine();
         }
         else {
            Console.WriteLine("   {0}: {1}", prop.Name, prop.GetValue(nfi1));
        }
      }
   }

   public int Compare(Object x, Object y)
   {
      if (x == null && y == null) return 0;

      PropertyInfo px = x as PropertyInfo;
      if (px == null) return -1;

      PropertyInfo py = y as PropertyInfo;
      if (py == null) return 1;

      return String.Compare(px.Name, py.Name);
   }
}
// The example displays the following output:
//       Objects equal: True
//       Equal references: True
//
//       Properties of NumberFormat.CurrentInfo object:
//          CurrencyDecimalDigits: 2
//          CurrencyDecimalSeparator: .
//          CurrencyGroupSeparator: ,
//          CurrencyGroupSizes: { 3 }
//          CurrencyNegativePattern: 0
//          CurrencyPositivePattern: 0
//          CurrencySymbol: $
//          DigitSubstitution: None
//          IsReadOnly: True
//          NaNSymbol: NaN
//          NativeDigits: { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }
//          NegativeInfinitySymbol: -Infinity
//          NegativeSign: -
//          NumberDecimalDigits: 2
//          NumberDecimalSeparator: .
//          NumberGroupSeparator: ,
//          NumberGroupSizes: { 3 }
//          NumberNegativePattern: 1
//          PercentDecimalDigits: 2
//          PercentDecimalSeparator: .
//          PercentGroupSeparator: ,
//          PercentGroupSizes: { 3 }
//          PercentNegativePattern: 0
//          PercentPositivePattern: 0
//          PercentSymbol: %
//          PerMilleSymbol: %
//          PositiveInfinitySymbol: Infinity
//          PositiveSign: +

Remarks

Retrieving a NumberFormatInfo object from the CurrentInfo property is equivalent to retrieving a NumberFormatInfo object from the CultureInfo.CurrentCulture.NumberFormat property.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

See also