Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

NumberFormatInfo.NumberGroupSeparator Property

Gets or sets the string that separates groups of digits to the left of the decimal in numeric values.

[Visual Basic]
Public Property NumberGroupSeparator As String
[C#]
public string NumberGroupSeparator {get; set;}
[C++]
public: __property String* get_NumberGroupSeparator();
public: __property void set_NumberGroupSeparator(String*);
[JScript]
public function get NumberGroupSeparator() : String;
public function set NumberGroupSeparator(String);

Property Value

The string that separates groups of digits to the left of the decimal in numeric values. The default for InvariantInfo is ",".

Exceptions

Exception Type Condition
ArgumentNullException The property is being set to a null reference (Nothing in Visual Basic).
InvalidOperationException The property is being set and the NumberFormatInfo is read-only.

Remarks

The initial value of this property is derived from the settings in Regional and Language Options (or Regional Options or Regional Settings) in Control Panel. However, if either NumberGroupSeparator or CurrencyGroupSeparator is the same as either NumberDecimalSeparator or CurrencyDecimalSeparator, ArgumentException is thrown during parsing.

Example

[Visual Basic, C#, C++] The following code example demonstrates the effect of changing the NumberGroupSeparator property.

[Visual Basic] 
Imports System
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 value with the default separator (",").
      Dim myInt As Int64 = 123456789
      Console.WriteLine(myInt.ToString("N", nfi))

      ' Displays the same value with a blank as the separator.
      nfi.NumberGroupSeparator = " "
      Console.WriteLine(myInt.ToString("N", nfi))

   End Sub 'Main 

End Class 'NumberFormatInfoSample


'This code produces the following output.

'

'123,456,789.00

'123 456 789.00



[C#] 
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 value with the default separator (",").
      Int64 myInt = 123456789;
      Console.WriteLine( myInt.ToString( "N", nfi ) );

      // Displays the same value with a blank as the separator.
      nfi.NumberGroupSeparator = " ";
      Console.WriteLine( myInt.ToString( "N", nfi ) );

   }
}


/* 
This code produces the following output.

123,456,789.00
123 456 789.00
*/
   

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;

int main()
{
   // Gets a NumberFormatInfo associated with the en-US culture.
   CultureInfo * MyCI = new CultureInfo(S"en-US", false);
   NumberFormatInfo* nfi = MyCI -> NumberFormat;

   // Displays a value with the default separator (S", ").
   Int64 myInt = 123456789;
   Console::WriteLine(myInt.ToString(S"N", nfi));

   // Displays the same value with a blank as the separator.
   nfi -> NumberGroupSeparator = S" ";
   Console::WriteLine(myInt.ToString(S"N", nfi));
}
/*
This code produces the following output.
123, 456, 789.00
123 456 789.00
*/

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

NumberFormatInfo Class | NumberFormatInfo Members | System.Globalization Namespace | NumberDecimalDigits | NumberDecimalSeparator | NumberGroupSizes | NaNSymbol | NumberNegativePattern | CurrencyGroupSeparator | PercentGroupSeparator

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft