NumberFormatInfo.NegativeSign 屬性

定義

取得或設定代表相關數字為負數的字串。Gets or sets the string that denotes that the associated number is negative.

public:
 property System::String ^ NegativeSign { System::String ^ get(); void set(System::String ^ value); };
public string NegativeSign { get; set; }
member this.NegativeSign : string with get, set
Public Property NegativeSign As String

屬性值

String

代表相關數字為負數的字串。The string that denotes that the associated number is negative. InvariantInfo 的預設值為 "-"。The default for InvariantInfo is "-".

例外狀況

此屬性設定為 nullThe property is being set to null.

正在設定屬性,而且 NumberFormatInfo 物件為唯讀。The property is being set and the NumberFormatInfo object is read-only.

範例

下列範例會具現化代表不因文化特性而異的讀寫 CultureInfo 物件,並將上劃線字元 (U + 203E) 指派給其 NegativeSign 屬性。The following example instantiates a read-write CultureInfo object that represents the invariant culture and assigns the OVERLINE character (U+203E) to its NegativeSign property. 然後,它會使用此 CultureInfo 物件來格式化負浮點數的陣列。It then uses this CultureInfo object to format an array of negative floating-point numbers.

using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      CultureInfo ci = CultureInfo.CreateSpecificCulture("");
      ci.NumberFormat.NegativeSign = "\u203E";
      double[] numbers = { -1.0, -16.3, -106.35 };

      foreach (var number in numbers)
         Console.WriteLine(number.ToString(culture));
   }
}
// The example displays the following output:
//       ‾1
//       ‾16.3
//       ‾106.35
Imports System.Globalization

Module Example
   Public Sub Main()
      Dim ci As CultureInfo = CultureInfo.CreateSpecificCulture("")
      ci.NumberFormat.NegativeSign = ChrW(&h203E)
      Dim numbers() As Double = { -1.0, -16.3, -106.35 }

      For Each number In numbers
         Console.WriteLine(number.ToString(culture))
      Next
   End Sub
End Module
' The example displays the following output:
'       ‾1
'       ‾16.3
'       ‾106.35

備註

此屬性同時用於格式設定和剖析作業。This property is used in both formatting and parsing operations. 如需有關如何在格式化作業中使用的詳細資訊,請參閱 標準數值格式字串自訂數值格式字串 主題。For more information on its use in formatting operations, see the Standard Numeric Format Strings and Custom Numeric Format Strings topics.

適用於

另請參閱