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 "-".
例外
该属性设置为 null
。The 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.