NumberFormatInfo.NegativeSign 屬性

定義

取得或設定代表相關數字為負數的字串。

C#
public string NegativeSign { get; set; }

屬性值

代表相關數字為負數的字串。 InvariantInfo 的預設值為 "-"。

例外狀況

正在將屬性設定為 null

正在設定屬性,而且 NumberFormatInfo 物件為唯讀。

範例

下列範例會具現化代表不變異文化特性的讀寫 CultureInfo 物件,並將 OVERLINE 字元指派給 NegativeSign 其屬性 (U+203E) 。 然後, CultureInfo 它會使用此物件來格式化負數浮點數的數位。

C#
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(ci));
   }
}
// The example displays the following output:
//       ‾1
//       ‾16.3
//       ‾106.35

備註

此屬性用於格式化和剖析作業。 如需格式化作業使用的詳細資訊,請參閱 標準數值格式字串自定義數值格式字串 主題。

適用於

產品 版本
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

另請參閱