NumberFormatInfo.NumberNegativePattern Property

Gets or sets the format pattern for negative numeric values.

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

public int NumberNegativePattern { get; set; }

Property Value

Type: System.Int32
The format pattern for negative numeric values. The default for InvariantInfo is 1, which represents "-n", where n is a number.

ExceptionCondition
ArgumentOutOfRangeException

The property is being set to a value that is less than 0 or greater than 4.

InvalidOperationException

The property is being set and the NumberFormatInfo object is read-only.

This property has one of the values in the following table. The symbol "-" is the NegativeSign and n is a number.

Value

Associated pattern

0

(n)

1

-n

2

- n

3

n-

4

n -

The following example prints a value using different NumberNegativePattern patterns.


using System;
using System.Globalization;
class Example
{

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

      // Creates a new NumberFormatinfo.
      NumberFormatInfo myNfi = new NumberFormatInfo();

      // Takes a negative value.
      Int64 myInt = -1234;

      // Displays the value with default formatting.
      outputBlock.Text += String.Format("Default  \t:\t{0}", myInt.ToString("N", myNfi)) + "\n";

      // Displays the value with other patterns.
      for (int i = 0; i <= 4; i++)
      {
         myNfi.NumberNegativePattern = i;
         outputBlock.Text += String.Format("Pattern {0}\t:\t{1}", myNfi.NumberNegativePattern, myInt.ToString("N", myNfi)) + "\n";
      }
   }
}
/*
This code produces the following output.

Default         :       (1,234.00)
Pattern 0       :       (1,234.00)
Pattern 1       :       -1,234.00
Pattern 2       :       - 1,234.00
Pattern 3       :       1,234.00-
Pattern 4       :       1,234.00 -
*/


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

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

Community Additions

ADD
Show: