NumberFormatInfo.NumberNegativePattern プロパティ
負の数値の形式パターンを取得または設定します。
Public Property NumberNegativePattern As Integer
[C#]
public int NumberNegativePattern {get; set;}
[C++]
public: __property int get_NumberNegativePattern();public: __property void set_NumberNegativePattern(int);
[JScript]
public function get NumberNegativePattern() : int;public function set NumberNegativePattern(int);
プロパティ値
負の数値の形式パターン。 InvariantInfo の既定値は 1 で、"-n" を表します。 n は数値です。
例外
例外の種類 | 条件 |
---|---|
ArgumentOutOfRangeException | プロパティが 0 より小さいか、4 より大きい値に設定されています。 |
InvalidOperationException | プロパティが設定されていますが、 NumberFormatInfo が読み取り専用です。 |
解説
このプロパティは、次の表の値のいずれか 1 つをとります。記号 "-" は 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 -
[C#]
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 -
*/
[C++]
#using <mscorlib.dll>
using namespace System;
using namespace System::Globalization;
int main()
{
// Creates a new NumberFormatinfo.
NumberFormatInfo* myNfi = new NumberFormatInfo();
// Takes a negative value.
Int64 myInt = -1234;
// Displays the value with default formatting.
Console::WriteLine(S"Default \t:\t {0}", myInt.ToString(S"N", myNfi));
// Displays the value with other patterns.
for (int i = 0; i <= 4; i++)
{
myNfi -> NumberNegativePattern = i;
Console::WriteLine(S"Pattern {0}\t:\t {1}",
__box(myNfi -> NumberNegativePattern),
myInt.ToString(S"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 -
*/
[JScript]
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 NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard
参照
NumberFormatInfo クラス | NumberFormatInfo メンバ | System.Globalization 名前空間 | NumberDecimalDigits | NumberDecimalSeparator | NumberGroupSeparator | NumberGroupSizes | NaNSymbol | CurrencyNegativePattern | PercentNegativePattern