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

屬性值

代表相關數字為負數的字串。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 + NegativeSign 203E)指派給其屬性。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.

適用於

另請參閱