NumberFormatInfo.NumberNegativePattern 属性

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

**命名空间:**System.Globalization
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Property NumberNegativePattern As Integer
用法
Dim instance As NumberFormatInfo
Dim value As Integer

value = instance.NumberNegativePattern

instance.NumberNegativePattern = value
public int NumberNegativePattern { get; set; }
public:
property int NumberNegativePattern {
    int get ();
    void set (int value);
}
/** @property */
public int get_NumberNegativePattern ()

/** @property */
public void set_NumberNegativePattern (int value)
public function get NumberNegativePattern () : int

public function set NumberNegativePattern (value : int)

属性值

负数值的格式模式。InvariantInfo 的默认值为 1,这表示“-n”,其中 n 是一个数字。

异常

异常类型 条件

ArgumentOutOfRangeException

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

InvalidOperationException

设置该属性,并且 NumberFormatInfo 是只读的。

备注

该属性可以具有下表中列出的其中一个值。符号“-”是 NegativeSign,并且 n 是一个数字。

关联的模式

0

(n)

1

-n

2

- n

3

n-

4

n -

示例

下面的代码示例打印使用不同 NumberNegativePattern 模式的值。

Imports System
Imports System.Globalization
Imports Microsoft.VisualBasic

Class SamplesNumberFormatInfo    
    
    Public Shared Sub Main()
        
        ' Creates a new NumberFormatinfo.
        Dim myNfi As New NumberFormatInfo()
        
        ' Takes a negative value.
        Dim myInt As Int64 = - 1234
        
        ' Displays the value with default formatting.
        Console.WriteLine("Default  " + ControlChars.Tab + ":" _
           + ControlChars.Tab + "{0}", myInt.ToString("N", myNfi))
        
        ' Displays the value with other patterns.
        Dim i As Integer
        For i = 0 To 4
            myNfi.NumberNegativePattern = i
            Console.WriteLine("Pattern {0}" + ControlChars.Tab + ":" _
               + ControlChars.Tab + "{1}", myNfi.NumberNegativePattern, _
               myInt.ToString("N", myNfi))
        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 SamplesNumberFormatInfo  {
 
    public static void Main()  {
 
       // Creates a new NumberFormatinfo.
       NumberFormatInfo myNfi = new NumberFormatInfo();

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

       // Displays the value with default formatting.
       Console.WriteLine( "Default  \t:\t{0}", myInt.ToString( "N", myNfi ) );

       // Displays the value with other patterns.
       for ( int i = 0; i <= 4; i++ )  {
          myNfi.NumberNegativePattern = i;
          Console.WriteLine( "Pattern {0}\t:\t{1}", myNfi.NumberNegativePattern, myInt.ToString( "N", myNfi ) );
       }
    }
 }
 /*
 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 namespace System;
using namespace System::Globalization;
int main()
{
   
   // Creates a new NumberFormatinfo.
   NumberFormatInfo^ myNfi = gcnew NumberFormatInfo;
   
   // Takes a negative value.
   Int64 myInt = -1234;
   
   // Displays the value with default formatting.
   Console::WriteLine( "Default  \t:\t {0}", myInt.ToString( "N", myNfi ) );
   
   // Displays the value with other patterns.
   for ( int i = 0; i <= 4; i++ )
   {
      myNfi->NumberNegativePattern = i;
      Console::WriteLine( "Pattern {0}\t:\t {1}", myNfi->NumberNegativePattern, myInt.ToString( "N", myNfi ) );

   }
}

/*
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 -
*/
import System.*;
import System.Globalization.*;

class SamplesNumberFormatInfo
{
    public static void main(String[] args)
    {
        // Creates a new NumberFormatinfo.
        NumberFormatInfo myNfi = new NumberFormatInfo();
        // Takes a negative value.
        Int64 myInt = (Int64)(-1234);
        // Displays the value with default formatting.
        Console.WriteLine("Default  \t:\t{0}", myInt.ToString("N", myNfi));
        // Displays the value with other patterns.
        for (int i = 0; i <= 4; i++) {
            myNfi.set_NumberNegativePattern(i);
            Console.WriteLine("Pattern {0}\t:\t{1}", (Int32)myNfi.
                get_NumberNegativePattern(), myInt.ToString("N", myNfi));
        }
    } //main
} //SamplesNumberFormatInfo

/*
 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 -
*/
import System
import System.Globalization

// Creates a new NumberFormatinfo.
var myNfi : NumberFormatInfo = new NumberFormatInfo()

// Takes a negative value.
var myInt : Int64 = - 1234

// Displays the value with default formatting.
Console.WriteLine("Default  \t:\t{0}", myInt.ToString("N", myNfi))

// Displays the value with other patterns.
for(var i = 0; i < 5; i++){
    myNfi.NumberNegativePattern = i
    Console.WriteLine("Pattern {0}\t:\t{1}", myNfi.NumberNegativePattern, myInt.ToString("N", myNfi))
}

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

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

NumberFormatInfo 类
NumberFormatInfo 成员
System.Globalization 命名空间
NumberFormatInfo.NumberDecimalDigits 属性
NumberFormatInfo.NumberDecimalSeparator 属性
NumberFormatInfo.NumberGroupSeparator 属性
NumberFormatInfo.NumberGroupSizes 属性
NumberFormatInfo.NaNSymbol 属性
NumberFormatInfo.CurrencyNegativePattern 属性
PercentNegativePattern