Condividi tramite


NumberFormatInfo.NumberNegativePattern Property

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

Gets or sets the format pattern for negative numeric values.

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

Syntax

'Declaration
Public Property NumberNegativePattern As Integer
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.

Exceptions

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.

Remarks

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 -

Examples

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 -
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 -
*/

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.