NumberFormatInfo.NumberNegativePattern 属性

定义

获取或设置负数值的格式模式。

public:
 property int NumberNegativePattern { int get(); void set(int value); };
public int NumberNegativePattern { get; set; }
member this.NumberNegativePattern : int with get, set
Public Property NumberNegativePattern As Integer

属性值

Int32

负数值的格式模式。

例外

该属性设置为一个小于 0 或大于 4 的值。

设置了该属性,但 NumberFormatInfo 对象为只读。

示例

以下示例使用不同的模式显示 NumberNegativePattern 值。

using namespace System;
using namespace System::Globalization;

int main()
{
   // Create a new NumberFormatinfo.
   NumberFormatInfo^ nfi = gcnew NumberFormatInfo;
   
   // Takes a negative value.
   Int64 value = -1234;
   
   // Displays the value with default formatting.
   Console::WriteLine("{0,-20} {1,-10}", "Default:", 
                          value.ToString("N", nfi));
   
   // Displays the value with other patterns.
   for (int i = 0; i <= 4; i++) {
      nfi->NumberNegativePattern = i;
      Console::WriteLine("{0,-20} {1,-10}", 
                              String::Format("Pattern {0}:", 
                                             nfi->NumberNegativePattern), 
                              value.ToString("N", nfi));
   }
}
// The example displays 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 Main()  {

       // Create a new NumberFormatinfo.
       NumberFormatInfo nfi = new NumberFormatInfo();

       // Define a negative value.
       Int64 value = -1234;

       // Display the value with default formatting.
        Console.WriteLine("{0,-20} {1,-10}", "Default:",
                          value.ToString("N", nfi));

       // Display the value with other patterns.
       for (int i = 0; i <= 4; i++)  {
          nfi.NumberNegativePattern = i;
            Console.WriteLine("{0,-20} {1,-10}",
                              string.Format("Pattern {0}:",
                                            nfi.NumberNegativePattern),
                              value.ToString("N", nfi));
       }
   }
}
// The example displays 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 -
Imports System.Globalization

Module Example
    Public Sub Main()
        ' Creates a new NumberFormatinfo.
        Dim nfi As New NumberFormatInfo()
        
        ' Define a negative value.
        Dim value As Int64 = -1234
        
        ' Display the value with default formatting.
        Console.WriteLine("{0,-20} {1,-10}", "Default:", 
                          value.ToString("N", nfi))
        
        ' Display the value with other patterns.
        For i As Integer = 0 To 4
            nfi.NumberNegativePattern = i
            Console.WriteLine("{0,-20} {1,-10}", 
                              String.Format("Pattern {0}:", 
                                            nfi.NumberNegativePattern), 
                              value.ToString("N", nfi))
        Next 
    End Sub
End Module
' The example displays 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 -

注解

属性定义使用"N"标准数字格式字符串格式化的负 NumberNegativePattern 值的格式。 此属性具有下表中的值之一。 符号"-"是 NegativeSignn 是数字。

“值” 关联的模式
0 (n)
1 -n
2 - n
3 n-
4 n -

属性返回的固定区域性的默认值为 InvariantInfo 1,表示"-n",其中 n 是数字。

适用于

另请参阅