Sdílet prostřednictvím


NumberFormatInfo.CurrencyNegativePattern Property

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

Gets or sets the format pattern for negative currency values.

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

Syntax

'Declaration
Public Property CurrencyNegativePattern As Integer
public int CurrencyNegativePattern { get; set; }

Property Value

Type: System.Int32
The format pattern for negative currency values. The default for InvariantInfo is 0, which represents "($n)", where "$" is the CurrencySymbol and n is a number.

Exceptions

Exception Condition
ArgumentOutOfRangeException

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

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 CurrencySymbol, the symbol "-" is the NegativeSign, and n is a number.

Value

Associated pattern

0

($n)

1

-$n

2

$-n

3

$n-

4

(n$)

5

-n$

6

n-$

7

n$-

8

-n $

9

-$ n

10

n $-

11

$ n-

12

$ -n

13

n- $

14

($ n)

15

(n $)

Examples

The following example formats a numeric value using each of the 16 possible values of the CurrencyNegativePattern property for the current culture.

Imports System.Globalization

Public Module Example
   Public Sub Demo(outputBlock As System.Windows.Controls.TextBlock)
      ' Create a read-write NumberFormatInfo object for the current culture.
      Dim numberInfo As NumberFormatInfo = DirectCast(NumberFormatInfo.CurrentInfo.Clone, _
                                                      NumberFormatInfo)
      Dim value As Decimal = -16.32d

      ' Assign each possible value to the CurrencyNegativePattern property.
      For ctr As Integer = 0 to 15
         numberInfo.CurrencyNegativePattern = ctr
         outputBlock.Text += String.Format("{0,2}: {1}", ctr, _
                                           value.ToString("C", numberInfo)) + vbCrLf
      Next
   End Sub
End Module
' The example displays the following output:
'        0: ($16.32)
'        1: -$16.32
'        2: $-16.32
'        3: $16.32-
'        4: (16.32$)
'        5: -16.32$
'        6: 16.32-$
'        7: 16.32$-
'        8: -16.32 $
'        9: -$ 16.32
'       10: 16.32 $-
'       11: $ 16.32-
'       12: $ -16.32
'       13: 16.32- $
'       14: ($ 16.32)
'       15: (16.32 $)
using System;
using System.Globalization;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      // Create a read-write NumberFormatInfo object for the current culture.
      NumberFormatInfo numberInfo = NumberFormatInfo.CurrentInfo.Clone() as NumberFormatInfo;
      decimal value = -16.32m;

      // Assign each possible value to the CurrencyNegativePattern property.
      for (int ctr = 0; ctr <= 15; ctr++)
      {
         numberInfo.CurrencyNegativePattern = ctr;
         outputBlock.Text += String.Format("{0,2}: {1}\n", ctr, 
                                           value.ToString("C", numberInfo));
      }
   }
}
// The example displays the following output:
//        0: ($16.32)
//        1: -$16.32
//        2: $-16.32
//        3: $16.32-
//        4: (16.32$)
//        5: -16.32$
//        6: 16.32-$
//        7: 16.32$-
//        8: -16.32 $
//        9: -$ 16.32
//       10: 16.32 $-
//       11: $ 16.32-
//       12: $ -16.32
//       13: 16.32- $
//       14: ($ 16.32)
//       15: (16.32 $)

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.