NumberFormatInfo.NumberNegativePattern Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets or sets the format pattern for negative numeric values.
Assembly: mscorlib (in mscorlib.dll)
Property Value
Type: System.Int32The format pattern for negative numeric values. The default for InvariantInfo is 1, which represents "-n", where n is a number.
| Exception | Condition |
|---|---|
| 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.
Imports System.Globalization Class Example Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) ' Creates a new NumberFormatinfo. Dim myNfi As New NumberFormatInfo() ' Takes a negative value. Dim myInt As Int64 = -1234 ' Displays the value with default formatting. outputBlock.Text += String.Format("Default " + ControlChars.Tab + ":" _ + ControlChars.Tab + "{0}", myInt.ToString("N", myNfi)) + vbCrLf ' Displays the value with other patterns. Dim i As Integer For i = 0 To 4 myNfi.NumberNegativePattern = i outputBlock.Text += String.Format("Pattern {0}" + ControlChars.Tab + ":" _ + ControlChars.Tab + "{1}", myNfi.NumberNegativePattern, _ myInt.ToString("N", myNfi)) + vbCrLf Next i End Sub End Class ' 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 -