Partager via


NumberFormatInfo.InvariantInfo Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets the default read-only NumberFormatInfo object that is culture-independent (invariant).

Namespace:  System.Globalization
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Shared ReadOnly Property InvariantInfo As NumberFormatInfo
public static NumberFormatInfo InvariantInfo { get; }

Property Value

Type: System.Globalization.NumberFormatInfo
The default read-only NumberFormatInfo object that is culture-independent (invariant).

Remarks

This property does not change, regardless of the current culture.

Examples

The following example displays the default property values of the InvariantInfo object.

Imports System.Globalization
Imports System.Text


Class Example


   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      ' Gets the InvariantInfo.
      Dim myInv As NumberFormatInfo = NumberFormatInfo.InvariantInfo

      ' Gets a UnicodeEncoding to display the Unicode value of symbols.
      Dim myUE As New UnicodeEncoding(True, False)
      Dim myCodes() As Byte

      ' Displays the default values for each of the properties.
      outputBlock.Text &= "InvariantInfo:" & vbCrLf
      outputBlock.Text += String.Format("Note: Symbols might not display correctly,") & vbCrLf
      outputBlock.Text += String.Format("therefore, Unicode values are included.") & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "CurrencyDecimalDigits" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.CurrencyDecimalDigits) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "CurrencyDecimalSeparator" + ControlChars.Tab + "{0}", myInv.CurrencyDecimalSeparator) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "CurrencyGroupSeparator" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.CurrencyGroupSeparator) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "CurrencyGroupSizes" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.CurrencyGroupSizes(0)) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "CurrencyNegativePattern" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.CurrencyNegativePattern) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "CurrencyPositivePattern" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.CurrencyPositivePattern) & vbCrLf
      myCodes = myUE.GetBytes(myInv.CurrencySymbol)
      outputBlock.Text += String.Format(ControlChars.Tab + "CurrencySymbol" + ControlChars.Tab + ControlChars.Tab + ControlChars.Tab + "{0}" + ControlChars.Tab + "(U+{1:x2}{2:x2})", myInv.CurrencySymbol, myCodes(0), myCodes(1)) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "NaNSymbol" + ControlChars.Tab + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.NaNSymbol) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "NegativeInfinitySymbol" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.NegativeInfinitySymbol) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "NegativeSign" + ControlChars.Tab + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.NegativeSign) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "NumberDecimalDigits" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.NumberDecimalDigits) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "NumberDecimalSeparator" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.NumberDecimalSeparator) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "NumberGroupSeparator" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.NumberGroupSeparator) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "NumberGroupSizes" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.NumberGroupSizes(0)) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "NumberNegativePattern" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.NumberNegativePattern) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "PercentDecimalDigits" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.PercentDecimalDigits) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "PercentDecimalSeparator" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.PercentDecimalSeparator) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "PercentGroupSeparator" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.PercentGroupSeparator) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "PercentGroupSizes" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.PercentGroupSizes(0)) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "PercentNegativePattern" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.PercentNegativePattern) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "PercentPositivePattern" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.PercentPositivePattern) & vbCrLf
      myCodes = myUE.GetBytes(myInv.PercentSymbol)
      outputBlock.Text += String.Format(ControlChars.Tab + "PercentSymbol" + ControlChars.Tab + ControlChars.Tab + ControlChars.Tab + "{0}" + ControlChars.Tab + "(U+{1:x2}{2:x2})", myInv.PercentSymbol, myCodes(0), myCodes(1)) & vbCrLf
      myCodes = myUE.GetBytes(myInv.PerMilleSymbol)
      outputBlock.Text += String.Format(ControlChars.Tab + "PerMilleSymbol" + ControlChars.Tab + ControlChars.Tab + ControlChars.Tab + "{0}" + ControlChars.Tab + "(U+{1:x2}{2:x2})", myInv.PerMilleSymbol, myCodes(0), myCodes(1)) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "PositiveInfinitySymbol" + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.PositiveInfinitySymbol) & vbCrLf
      outputBlock.Text += String.Format(ControlChars.Tab + "PositiveSign" + ControlChars.Tab + ControlChars.Tab + ControlChars.Tab + "{0}", myInv.PositiveSign) & vbCrLf
   End Sub 'Main 
End Class 'SamplesNumberFormatInfo


' This code produces the following output.
'
' InvariantInfo:
' Note: Symbols might not display correctly,
' therefore, Unicode values are included.
'         CurrencyDecimalDigits           2
'         CurrencyDecimalSeparator        .
'         CurrencyGroupSeparator          ,
'         CurrencyGroupSizes              3
'         CurrencyNegativePattern         0
'         CurrencyPositivePattern         0
'         CurrencySymbol                         (U+00a4)
'         NaNSymbol                       NaN
'         NegativeInfinitySymbol          -Infinity
'         NegativeSign                    -
'         NumberDecimalDigits             2
'         NumberDecimalSeparator          .
'         NumberGroupSeparator            ,
'         NumberGroupSizes                3
'         NumberNegativePattern           1
'         PercentDecimalDigits            2
'         PercentDecimalSeparator         .
'         PercentGroupSeparator           ,
'         PercentGroupSizes               3
'         PercentNegativePattern          0
'         PercentPositivePattern          0
'         PercentSymbol                   %       (U+0025)
'         PerMilleSymbol                  %       (U+2030)
'         PositiveInfinitySymbol          Infinity
'         PositiveSign                    +
using System;
using System.Globalization;
using System.Text;

class Example
{

   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {

      // Gets the InvariantInfo.
      NumberFormatInfo myInv = NumberFormatInfo.InvariantInfo;

      // Gets a UnicodeEncoding to display the Unicode value of symbols.
      UnicodeEncoding myUE = new UnicodeEncoding(true, false);
      byte[] myCodes;

      // Displays the default values for each of the properties.
      outputBlock.Text += String.Format("InvariantInfo:\nNote: Symbols might not display correctly,\ntherefore, Unicode values are included.") + "\n";
      outputBlock.Text += String.Format("\tCurrencyDecimalDigits\t\t{0}", myInv.CurrencyDecimalDigits) + "\n";
      outputBlock.Text += String.Format("\tCurrencyDecimalSeparator\t{0}", myInv.CurrencyDecimalSeparator) + "\n";
      outputBlock.Text += String.Format("\tCurrencyGroupSeparator\t\t{0}", myInv.CurrencyGroupSeparator) + "\n";
      outputBlock.Text += String.Format("\tCurrencyGroupSizes\t\t{0}", myInv.CurrencyGroupSizes[0]) + "\n";
      outputBlock.Text += String.Format("\tCurrencyNegativePattern\t\t{0}", myInv.CurrencyNegativePattern) + "\n";
      outputBlock.Text += String.Format("\tCurrencyPositivePattern\t\t{0}", myInv.CurrencyPositivePattern) + "\n";
      myCodes = myUE.GetBytes(myInv.CurrencySymbol);
      outputBlock.Text += String.Format("\tCurrencySymbol\t\t\t{0}\t(U+{1:x2}{2:x2})", myInv.CurrencySymbol, myCodes[0], myCodes[1]) + "\n";
      outputBlock.Text += String.Format("\tNaNSymbol\t\t\t{0}", myInv.NaNSymbol) + "\n";
      outputBlock.Text += String.Format("\tNegativeInfinitySymbol\t\t{0}", myInv.NegativeInfinitySymbol) + "\n";
      outputBlock.Text += String.Format("\tNegativeSign\t\t\t{0}", myInv.NegativeSign) + "\n";
      outputBlock.Text += String.Format("\tNumberDecimalDigits\t\t{0}", myInv.NumberDecimalDigits) + "\n";
      outputBlock.Text += String.Format("\tNumberDecimalSeparator\t\t{0}", myInv.NumberDecimalSeparator) + "\n";
      outputBlock.Text += String.Format("\tNumberGroupSeparator\t\t{0}", myInv.NumberGroupSeparator) + "\n";
      outputBlock.Text += String.Format("\tNumberGroupSizes\t\t{0}", myInv.NumberGroupSizes[0]) + "\n";
      outputBlock.Text += String.Format("\tNumberNegativePattern\t\t{0}", myInv.NumberNegativePattern) + "\n";
      outputBlock.Text += String.Format("\tPercentDecimalDigits\t\t{0}", myInv.PercentDecimalDigits) + "\n";
      outputBlock.Text += String.Format("\tPercentDecimalSeparator\t\t{0}", myInv.PercentDecimalSeparator) + "\n";
      outputBlock.Text += String.Format("\tPercentGroupSeparator\t\t{0}", myInv.PercentGroupSeparator) + "\n";
      outputBlock.Text += String.Format("\tPercentGroupSizes\t\t{0}", myInv.PercentGroupSizes[0]) + "\n";
      outputBlock.Text += String.Format("\tPercentNegativePattern\t\t{0}", myInv.PercentNegativePattern) + "\n";
      outputBlock.Text += String.Format("\tPercentPositivePattern\t\t{0}", myInv.PercentPositivePattern) + "\n";
      myCodes = myUE.GetBytes(myInv.PercentSymbol);
      outputBlock.Text += String.Format("\tPercentSymbol\t\t\t{0}\t(U+{1:x2}{2:x2})", myInv.PercentSymbol, myCodes[0], myCodes[1]) + "\n";
      myCodes = myUE.GetBytes(myInv.PerMilleSymbol);
      outputBlock.Text += String.Format("\tPerMilleSymbol\t\t\t{0}\t(U+{1:x2}{2:x2})", myInv.PerMilleSymbol, myCodes[0], myCodes[1]) + "\n";
      outputBlock.Text += String.Format("\tPositiveInfinitySymbol\t\t{0}", myInv.PositiveInfinitySymbol) + "\n";
      outputBlock.Text += String.Format("\tPositiveSign\t\t\t{0}", myInv.PositiveSign) + "\n";

   }
}


/*

This code produces the following output.

InvariantInfo:
Note: Symbols might not display correctly,
therefore, Unicode values are included.
        CurrencyDecimalDigits           2
        CurrencyDecimalSeparator        .
        CurrencyGroupSeparator          ,
        CurrencyGroupSizes              3
        CurrencyNegativePattern         0
        CurrencyPositivePattern         0
        CurrencySymbol                         (U+00a4)
        NaNSymbol                       NaN
        NegativeInfinitySymbol          -Infinity
        NegativeSign                    -
        NumberDecimalDigits             2
        NumberDecimalSeparator          .
        NumberGroupSeparator            ,
        NumberGroupSizes                3
        NumberNegativePattern           1
        PercentDecimalDigits            2
        PercentDecimalSeparator         .
        PercentGroupSeparator           ,
        PercentGroupSizes               3
        PercentNegativePattern          0
        PercentPositivePattern          0
        PercentSymbol                   %       (U+0025)
        PerMilleSymbol                  %       (U+2030)
        PositiveInfinitySymbol          Infinity
        PositiveSign                    +

*/

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.