Decimal Decimal Decimal Decimal Struct

定义

表示十进制浮点数。Represents a decimal floating-point number.

public value class Decimal : IComparable, IComparable<System::Decimal>, IConvertible, IEquatable<System::Decimal>, IFormattable, System::Runtime::Serialization::IDeserializationCallback
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public struct Decimal : IComparable, IComparable<decimal>, IConvertible, IEquatable<decimal>, IFormattable, System.Runtime.Serialization.IDeserializationCallback
type decimal = struct
    interface IFormattable
    interface IConvertible
    interface IDeserializationCallback
Public Structure Decimal
Implements IComparable, IComparable(Of Decimal), IConvertible, IDeserializationCallback, IEquatable(Of Decimal), IFormattable
继承
属性
实现

示例

以下代码示例演示了 Decimal 的用法。The following code example demonstrates the use of Decimal.

   /// <summary>
   /// Keeping my fortune in Decimals to avoid the round-off errors.
   /// </summary>
   public ref class PiggyBank
   {
   protected:
      Decimal MyFortune;

   public:
      void AddPenny()
      {
         MyFortune = System::Decimal::Add( MyFortune, Decimal(.01) );
      }

      System::Decimal Capacity()
      {
         return MyFortune.MaxValue;
      }

      Decimal Dollars()
      {
         return Decimal::Floor( MyFortune );
      }

      Decimal Cents()
      {
         return Decimal::Subtract( MyFortune, Decimal::Floor( MyFortune ) );
      }

      virtual System::String^ ToString() override
      {
         return MyFortune.ToString("C")+" in piggy bank";
      }
   };
}
/// <summary>
/// Keeping my fortune in Decimals to avoid the round-off errors.
/// </summary>
class PiggyBank {
    protected decimal MyFortune;

    public void AddPenny() {
        MyFortune = Decimal.Add(MyFortune, .01m);
    }

    public decimal Capacity {
        get {
            return Decimal.MaxValue;
        }
    }

    public decimal Dollars {
        get {
            return Decimal.Floor(MyFortune);
        }
    }

    public decimal Cents {
        get {
            return Decimal.Subtract(MyFortune, Decimal.Floor(MyFortune));
        }
    }

    public override string ToString() {
        return MyFortune.ToString("C")+" in piggy bank";
    }
}
' Keeping my fortune in Decimals to avoid the round-off errors.
Class PiggyBank
    Protected MyFortune As Decimal

    Public Sub AddPenny()
        MyFortune = [Decimal].Add(MyFortune, 0.01D)
    End Sub

    Public ReadOnly Property Capacity() As Decimal
        Get
            Return [Decimal].MaxValue
        End Get
    End Property

    Public ReadOnly Property Dollars() As Decimal
        Get
            Return [Decimal].Floor(MyFortune)
        End Get
    End Property

    Public ReadOnly Property Cents() As Decimal
        Get
            Return [Decimal].Subtract(MyFortune, [Decimal].Floor(MyFortune))
        End Get
    End Property

    Public Overrides Function ToString() As String
        Return MyFortune.ToString("C") + " in piggy bank"
    End Function
End Class

注解

Decimal 值类型表示介于正 79,228,162,514,264,337,593,543,950,335 和负 79,228,162,514,264,337,593,543,950,335 之间的十进制数字。The Decimal value type represents decimal numbers ranging from positive 79,228,162,514,264,337,593,543,950,335 to negative 79,228,162,514,264,337,593,543,950,335. Decimal 的默认值为 0。The default value of a Decimal is 0. Decimal值类型适用于需要大量重要整数和小数位且不会出现舍入错误的财务计算。The Decimal value type is appropriate for financial calculations that require large numbers of significant integral and fractional digits and no round-off errors. Decimal 类型仍需要舍入,但它最大限度地减少了因舍入而导致的错误。The Decimal type does not eliminate the need for rounding. 相反,它最大限度地减少了因舍入而导致的错误。Rather, it minimizes errors due to rounding. 例如,下面的代码生成 0.9999999999999999999999999999 的结果,而不是 1。For example, the following code produces a result of 0.9999999999999999999999999999 instead of 1.

using namespace System;

void main()
{
   Decimal dividend = Decimal::One;
   Decimal divisor = 3;
   // The following displays 0.9999999999999999999999999999 to the console
   Console::WriteLine(dividend/divisor * divisor);   
}
decimal dividend = Decimal.One;
decimal divisor = 3;
// The following displays 0.9999999999999999999999999999 to the console
Console.WriteLine(dividend/divisor * divisor);   
Dim dividend As Decimal = Decimal.One
Dim divisor As Decimal = 3
' The following displays 0.9999999999999999999999999999 to the console
Console.WriteLine(dividend/divisor * divisor)   

当除法和乘法的结果传递给Round方法时,结果将不会产生精度损失,如以下代码所示。When the result of the division and multiplication is passed to the Round method, the result suffers no loss of precision, as the following code shows.

using namespace System;


void main()
{
   Decimal dividend = Decimal::One;
   Decimal divisor = 3;
   // The following displays 1.00 to the console
   Console::WriteLine(Math::Round(dividend/divisor * divisor, 2));   	
}
decimal dividend = Decimal.One;
decimal divisor = 3;
// The following displays 1.00 to the console
Console.WriteLine(Math.Round(dividend/divisor * divisor, 2));   
Dim dividend As Decimal = Decimal.One
Dim divisor As Decimal = 3
' The following displays 1.00 to the console
Console.WriteLine(Math.Round(dividend/divisor * divisor, 2))   

小数是一个浮点值,其中包含一个符号、一个数字值,其中的每个数字的范围为0到9,而缩放因子指示将整数和小数部分分隔的浮点小数点的位置。数值。A decimal number is a floating-point value that consists of a sign, a numeric value where each digit in the value ranges from 0 to 9, and a scaling factor that indicates the position of a floating decimal point that separates the integral and fractional parts of the numeric value.

Decimal值的二进制表示形式由1位符号、96位整数和比例因子组成,用于划分96位整数,并指定它的哪一部分是小数部分。The binary representation of a Decimal value consists of a 1-bit sign, a 96-bit integer number, and a scaling factor used to divide the 96-bit integer and specify what portion of it is a decimal fraction. 缩放系数隐式为数字10,指数范围为0到28。The scaling factor is implicitly the number 10, raised to an exponent ranging from 0 to 28. Decimal因此,值的二进制表示形式((-296到 296)/10(0到28)),其中-( MinValue296-1)等于,296-1 等于MaxValueTherefore, the binary representation of a Decimal value the form, ((-296 to 296) / 10(0 to 28)), where -(296-1) is equal to MinValue, and 296-1 is equal to MaxValue. 有关Decimal值的二进制表示形式和示例的详细信息, Decimal(Int32[])请参阅构造函数和GetBits方法。For more information about the binary representation of Decimal values and an example, see the Decimal(Int32[]) constructor and the GetBits method.

缩放系数还保留数字中的Decimal任何尾随零。The scaling factor also preserves any trailing zeros in a Decimal number. 尾随零不会影响算术或比较运算Decimal中数值的值。Trailing zeros do not affect the value of a Decimal number in arithmetic or comparison operations. 但是,如果应用了适当的格式字符串ToString ,则方法可能会显示尾随零。However, trailing zeros might be revealed by the ToString method if an appropriate format string is applied.

转换注意事项Conversion Considerations

此类型提供将值与Decimal Int32 Int16 、、Int64、、 Byte 、、UInt64和值相互转换的方法。 UInt16 UInt32 SByteThis type provides methods that convert Decimal values to and from SByte, Int16, Int32, Int64, Byte, UInt16, UInt32, and UInt64 values. 从这些整型类型到Decimal的转换是不会丢失信息或引发异常的扩大转换。Conversions from these integral types to Decimal are widening conversions that never lose information or throw exceptions.

Decimal到任何整型的转换都是将Decimal值舍入为最接近的整数值的收缩转换。Conversions from Decimal to any of the integral types are narrowing conversions that round the Decimal value to the nearest integer value toward zero. 某些语言(如C#)还支持将Decimal值转换为Char值。Some languages, such as C#, also support the conversion of Decimal values to Char values. 如果无法在目标类型中表示这些转换的结果, OverflowException则会引发异常。If the result of these conversions cannot be represented in the destination type, an OverflowException exception is thrown.

Decimal类型还提供了一些方法Decimal ,这些方法可将Double值转换为和源Single和值。The Decimal type also provides methods that convert Decimal values to and from Single and Double values. Decimal转换为SingleDouble是收缩转换,这些转换可能会丢失精度,而不是有关转换后的值的大小的信息。Conversions from Decimal to Single or Double are narrowing conversions that might lose precision but not information about the magnitude of the converted value. 转换不会引发异常。The conversion does not throw an exception.

Single Double Decimal 如果转换OverflowException结果不能表示为,则从或到的转换会引发异常。 DecimalConversions from Single or Double to Decimal throw an OverflowException exception if the result of the conversion cannot be represented as a Decimal.

对十进制值执行运算Performing Operations on Decimal Values

Decimal类型支持标准数学运算,如加法、减法、除法、乘法和一元求反。The Decimal type supports standard mathematical operations such as addition, subtraction, division, multiplication, and unary negation. Decimal 通过GetBits调用方法,还可以直接使用值的二进制表示形式。You can also work directly with the binary representation of a Decimal value by calling the GetBits method.

若要比较Decimal两个值,可以使用标准数值比较运算符,也可以CompareTo调用或Equals方法。To compare two Decimal values, you can use the standard numeric comparison operators, or you can call the CompareTo or Equals method.

还可以调用Math类的成员来执行各种数值操作,包括获取数字的绝对值、确定两个Decimal值的最大值或最小值、获取数字的符号和舍入数字。You can also call the members of the Math class to perform a wide range of numeric operations, including getting the absolute value of a number, determining the maximum or minimum value of two Decimal values, getting the sign of a number, and rounding a number.

构造函数

Decimal(Double) Decimal(Double) Decimal(Double) Decimal(Double)

Decimal 的新实例初始化为指定的双精度浮点数的值。Initializes a new instance of Decimal to the value of the specified double-precision floating-point number.

Decimal(Int32) Decimal(Int32) Decimal(Int32) Decimal(Int32)

Decimal 的新实例初始化为指定的 32 位有符号整数的值。Initializes a new instance of Decimal to the value of the specified 32-bit signed integer.

Decimal(Int32[]) Decimal(Int32[]) Decimal(Int32[]) Decimal(Int32[])

Decimal 的新实例初始化为以二进制表示的、包含在指定数组中的十进制值。Initializes a new instance of Decimal to a decimal value represented in binary and contained in a specified array.

Decimal(Int64) Decimal(Int64) Decimal(Int64) Decimal(Int64)

Decimal 的新实例初始化为指定的 64 位有符号整数的值。Initializes a new instance of Decimal to the value of the specified 64-bit signed integer.

Decimal(Single) Decimal(Single) Decimal(Single) Decimal(Single)

Decimal 的新实例初始化为指定的单精度浮点数的值。Initializes a new instance of Decimal to the value of the specified single-precision floating-point number.

Decimal(UInt32) Decimal(UInt32) Decimal(UInt32) Decimal(UInt32)

Decimal 的新实例初始化为指定的 32 位无符号整数的值。Initializes a new instance of Decimal to the value of the specified 32-bit unsigned integer.

Decimal(UInt64) Decimal(UInt64) Decimal(UInt64) Decimal(UInt64)

Decimal 的新实例初始化为指定的 64 位无符号整数的值。Initializes a new instance of Decimal to the value of the specified 64-bit unsigned integer.

Decimal(Int32, Int32, Int32, Boolean, Byte) Decimal(Int32, Int32, Int32, Boolean, Byte) Decimal(Int32, Int32, Int32, Boolean, Byte) Decimal(Int32, Int32, Int32, Boolean, Byte)

用指定实例构成部分的参数来初始化 Decimal 的新实例。Initializes a new instance of Decimal from parameters specifying the instance's constituent parts.

字段

MaxValue MaxValue MaxValue MaxValue

表示 Decimal 的最大可能值。Represents the largest possible value of Decimal. 该字段是常数且为只读。This field is constant and read-only.

MinusOne MinusOne MinusOne MinusOne

表示数字负一 (-1)。Represents the number negative one (-1).

MinValue MinValue MinValue MinValue

表示 Decimal 的最小可能值。Represents the smallest possible value of Decimal. 该字段是常数且为只读。This field is constant and read-only.

One One One One

表示数字一 (1)。Represents the number one (1).

Zero Zero Zero Zero

表示数字零 (0)。Represents the number zero (0).

方法

Add(Decimal, Decimal) Add(Decimal, Decimal) Add(Decimal, Decimal) Add(Decimal, Decimal)

将两个指定的 Decimal 值相加。Adds two specified Decimal values.

Ceiling(Decimal) Ceiling(Decimal) Ceiling(Decimal) Ceiling(Decimal)

返回大于或等于指定的十进制数的最小整数值。Returns the smallest integral value that is greater than or equal to the specified decimal number.

Compare(Decimal, Decimal) Compare(Decimal, Decimal) Compare(Decimal, Decimal) Compare(Decimal, Decimal)

比较两个指定的 Decimal 值。Compares two specified Decimal values.

CompareTo(Decimal) CompareTo(Decimal) CompareTo(Decimal) CompareTo(Decimal)

将此实例与指定的 Decimal 对象进行比较并返回一个对二者的相对值的比较。Compares this instance to a specified Decimal object and returns a comparison of their relative values.

CompareTo(Object) CompareTo(Object) CompareTo(Object) CompareTo(Object)

将此实例与指定对象进行比较并返回一个对二者的相对值的比较。Compares this instance to a specified object and returns a comparison of their relative values.

Divide(Decimal, Decimal) Divide(Decimal, Decimal) Divide(Decimal, Decimal) Divide(Decimal, Decimal)

将两个指定的 Decimal 值相除。Divides two specified Decimal values.

Equals(Decimal) Equals(Decimal) Equals(Decimal) Equals(Decimal)

返回一个值,该值指示此实例和指定的 Decimal 对象是否表示相同的值。Returns a value indicating whether this instance and a specified Decimal object represent the same value.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

返回一个值,该值指示此实例和指定的 Object 是否表示相同的类型和值。Returns a value indicating whether this instance and a specified Object represent the same type and value.

Equals(Decimal, Decimal) Equals(Decimal, Decimal) Equals(Decimal, Decimal) Equals(Decimal, Decimal)

返回一个值,该值指示 Decimal 的两个指定实例是否表示同一个值。Returns a value indicating whether two specified instances of Decimal represent the same value.

Floor(Decimal) Floor(Decimal) Floor(Decimal) Floor(Decimal)

将指定的 Decimal 数字向负无穷方向舍入为最接近的整数。Rounds a specified Decimal number to the closest integer toward negative infinity.

FromOACurrency(Int64) FromOACurrency(Int64) FromOACurrency(Int64) FromOACurrency(Int64)

将指定的 64 位有符号整数(它包含 OLE 自动化货币值)转换为等效的 Decimal 值。Converts the specified 64-bit signed integer, which contains an OLE Automation Currency value, to the equivalent Decimal value.

GetBits(Decimal) GetBits(Decimal) GetBits(Decimal) GetBits(Decimal)

Decimal 的指定实例的值转换为其等效的二进制表示形式。Converts the value of a specified instance of Decimal to its equivalent binary representation.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

返回此实例的哈希代码。Returns the hash code for this instance.

GetTypeCode() GetTypeCode() GetTypeCode() GetTypeCode()

返回值类型 TypeCodeDecimalReturns the TypeCode for value type Decimal.

Multiply(Decimal, Decimal) Multiply(Decimal, Decimal) Multiply(Decimal, Decimal) Multiply(Decimal, Decimal)

两个指定的 Decimal 值相乘。Multiplies two specified Decimal values.

Negate(Decimal) Negate(Decimal) Negate(Decimal) Negate(Decimal)

返回指定的 Decimal 值乘以 -1 的结果。Returns the result of multiplying the specified Decimal value by negative one.

Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider) Parse(String, NumberStyles, IFormatProvider)

使用指定样式和区域性特定格式将数字的字符串表示形式转换为其 Decimal 等效项。Converts the string representation of a number to its Decimal equivalent using the specified style and culture-specific format.

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)
Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider) Parse(String, IFormatProvider)

使用指定的区域性特定格式信息将数字的字符串表示形式转换为其 Decimal 等效项。Converts the string representation of a number to its Decimal equivalent using the specified culture-specific format information.

Parse(String, NumberStyles) Parse(String, NumberStyles) Parse(String, NumberStyles) Parse(String, NumberStyles)

将指定样式的数字的字符串表示形式转换为它的等效 DecimalConverts the string representation of a number in a specified style to its Decimal equivalent.

Parse(String) Parse(String) Parse(String) Parse(String)

将数字的字符串表示形式转换为它的等效 Decimal 表示形式。Converts the string representation of a number to its Decimal equivalent.

Remainder(Decimal, Decimal) Remainder(Decimal, Decimal) Remainder(Decimal, Decimal) Remainder(Decimal, Decimal)

计算两个 Decimal 值相除后的余数。Computes the remainder after dividing two Decimal values.

Round(Decimal) Round(Decimal) Round(Decimal) Round(Decimal)

将小数值舍入到最接近的整数。Rounds a decimal value to the nearest integer.

Round(Decimal, Int32) Round(Decimal, Int32) Round(Decimal, Int32) Round(Decimal, Int32)

Decimal 值舍入到指定的小数位数。Rounds a Decimal value to a specified number of decimal places.

Round(Decimal, MidpointRounding) Round(Decimal, MidpointRounding) Round(Decimal, MidpointRounding) Round(Decimal, MidpointRounding)

将小数值舍入到最接近的整数。Rounds a decimal value to the nearest integer. 一个参数,指定当一个值正好处于另两个数中间时如何舍入这个值。A parameter specifies how to round the value if it is midway between two other numbers.

Round(Decimal, Int32, MidpointRounding) Round(Decimal, Int32, MidpointRounding) Round(Decimal, Int32, MidpointRounding) Round(Decimal, Int32, MidpointRounding)

将小数值舍入到指定精度。Rounds a decimal value to a specified precision. 一个参数,指定当一个值正好处于另两个数中间时如何舍入这个值。A parameter specifies how to round the value if it is midway between two other numbers.

Subtract(Decimal, Decimal) Subtract(Decimal, Decimal) Subtract(Decimal, Decimal) Subtract(Decimal, Decimal)

从一个 Decimal 值中减去指定的另一个值。Subtracts one specified Decimal value from another.

ToByte(Decimal) ToByte(Decimal) ToByte(Decimal) ToByte(Decimal)

将指定的 Decimal 的值转换为等效的 8 位无符号整数。Converts the value of the specified Decimal to the equivalent 8-bit unsigned integer.

ToDouble(Decimal) ToDouble(Decimal) ToDouble(Decimal) ToDouble(Decimal)

将指定的 Decimal 的值转换为等效的双精度浮点数。Converts the value of the specified Decimal to the equivalent double-precision floating-point number.

ToInt16(Decimal) ToInt16(Decimal) ToInt16(Decimal) ToInt16(Decimal)

将指定的 Decimal 值转换为等效的 16 位有符号整数。Converts the value of the specified Decimal to the equivalent 16-bit signed integer.

ToInt32(Decimal) ToInt32(Decimal) ToInt32(Decimal) ToInt32(Decimal)

将指定的 Decimal 值转换为等效的 32 位有符号整数。Converts the value of the specified Decimal to the equivalent 32-bit signed integer.

ToInt64(Decimal) ToInt64(Decimal) ToInt64(Decimal) ToInt64(Decimal)

将指定的 Decimal 值转换为等效的 64 位有符号整数。Converts the value of the specified Decimal to the equivalent 64-bit signed integer.

ToOACurrency(Decimal) ToOACurrency(Decimal) ToOACurrency(Decimal) ToOACurrency(Decimal)

将指定的 Decimal 值转换为等效的 OLE 自动化货币值,该值包含在一个 64 位有符号整数中。Converts the specified Decimal value to the equivalent OLE Automation Currency value, which is contained in a 64-bit signed integer.

ToSByte(Decimal) ToSByte(Decimal) ToSByte(Decimal) ToSByte(Decimal)

将指定的 Decimal 值转换为等效的 8 位有符号整数。Converts the value of the specified Decimal to the equivalent 8-bit signed integer.

ToSingle(Decimal) ToSingle(Decimal) ToSingle(Decimal) ToSingle(Decimal)

将指定的 Decimal 的值转换为等效的单精度浮点数。Converts the value of the specified Decimal to the equivalent single-precision floating-point number.

ToString(IFormatProvider) ToString(IFormatProvider) ToString(IFormatProvider) ToString(IFormatProvider)

使用指定的区域性特定格式信息,将此实例的数值转换为它的等效字符串表示形式。Converts the numeric value of this instance to its equivalent string representation using the specified culture-specific format information.

ToString(String, IFormatProvider) ToString(String, IFormatProvider) ToString(String, IFormatProvider) ToString(String, IFormatProvider)

使用指定的格式和区域性特定格式信息,将此实例的数值转换为它的等效字符串表示形式。Converts the numeric value of this instance to its equivalent string representation using the specified format and culture-specific format information.

ToString(String) ToString(String) ToString(String) ToString(String)

使用指定的格式,将此实例的数值转换为它的等效字符串表示形式。Converts the numeric value of this instance to its equivalent string representation, using the specified format.

ToString() ToString() ToString() ToString()

将此实例的数值转换为其等效的字符串表示形式。Converts the numeric value of this instance to its equivalent string representation.

ToUInt16(Decimal) ToUInt16(Decimal) ToUInt16(Decimal) ToUInt16(Decimal)

将指定的 Decimal 的值转换为等效的 16 位无符号整数。Converts the value of the specified Decimal to the equivalent 16-bit unsigned integer.

ToUInt32(Decimal) ToUInt32(Decimal) ToUInt32(Decimal) ToUInt32(Decimal)

将指定的 Decimal 的值转换为等效的 32 位无符号整数。Converts the value of the specified Decimal to the equivalent 32-bit unsigned integer.

ToUInt64(Decimal) ToUInt64(Decimal) ToUInt64(Decimal) ToUInt64(Decimal)

将指定的 Decimal 的值转换为等效的 64 位无符号整数。Converts the value of the specified Decimal to the equivalent 64-bit unsigned integer.

Truncate(Decimal) Truncate(Decimal) Truncate(Decimal) Truncate(Decimal)

返回指定的 Decimal 的整数位,所有小数位均被放弃。Returns the integral digits of the specified Decimal; any fractional digits are discarded.

TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider) TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider) TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider) TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)
TryParse(String, NumberStyles, IFormatProvider, Decimal) TryParse(String, NumberStyles, IFormatProvider, Decimal) TryParse(String, NumberStyles, IFormatProvider, Decimal) TryParse(String, NumberStyles, IFormatProvider, Decimal)

使用指定样式和区域性特定格式将数字的字符串表示形式转换为其 Decimal 等效项。Converts the string representation of a number to its Decimal equivalent using the specified style and culture-specific format. 一个指示转换是否成功的返回值。A return value indicates whether the conversion succeeded or failed.

TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Decimal) TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Decimal) TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Decimal) TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, Decimal)
TryParse(ReadOnlySpan<Char>, Decimal) TryParse(ReadOnlySpan<Char>, Decimal) TryParse(ReadOnlySpan<Char>, Decimal) TryParse(ReadOnlySpan<Char>, Decimal)
TryParse(String, Decimal) TryParse(String, Decimal) TryParse(String, Decimal) TryParse(String, Decimal)

将数字的字符串表示形式转换为它的等效 Decimal 表示形式。Converts the string representation of a number to its Decimal equivalent. 一个指示转换是否成功的返回值。A return value indicates whether the conversion succeeded or failed.

操作员

Addition(Decimal, Decimal) Addition(Decimal, Decimal) Addition(Decimal, Decimal) Addition(Decimal, Decimal)

将两个指定的 Decimal 值相加。Adds two specified Decimal values.

Decrement(Decimal) Decrement(Decimal) Decrement(Decimal) Decrement(Decimal)

Decimal 操作数减 1。Decrements the Decimal operand by one.

Division(Decimal, Decimal) Division(Decimal, Decimal) Division(Decimal, Decimal) Division(Decimal, Decimal)

将两个指定的 Decimal 值相除。Divides two specified Decimal values.

Equality(Decimal, Decimal) Equality(Decimal, Decimal) Equality(Decimal, Decimal) Equality(Decimal, Decimal)

返回一个值,该值指示两个 Decimal 值是否相等。Returns a value that indicates whether two Decimal values are equal.

Explicit(Single to Decimal) Explicit(Single to Decimal) Explicit(Single to Decimal) Explicit(Single to Decimal)

定义从单精度浮点数到 Decimal 的显式转换。Defines an explicit conversion of a single-precision floating-point number to a Decimal.

Explicit(Double to Decimal) Explicit(Double to Decimal) Explicit(Double to Decimal) Explicit(Double to Decimal)

定义从双精度浮点数到 Decimal 的显式转换。Defines an explicit conversion of a double-precision floating-point number to a Decimal.

Explicit(Decimal to UInt32) Explicit(Decimal to UInt32) Explicit(Decimal to UInt32) Explicit(Decimal to UInt32)

定义从 Decimal 到 32 位无符号整数的显式转换。Defines an explicit conversion of a Decimal to a 32-bit unsigned integer.

此 API 不兼容 CLS。This API is not CLS-compliant.

Explicit(Decimal to UInt16) Explicit(Decimal to UInt16) Explicit(Decimal to UInt16) Explicit(Decimal to UInt16)

定义从 Decimal 到 16 位无符号整数的显式转换。Defines an explicit conversion of a Decimal to a 16-bit unsigned integer.

此 API 不兼容 CLS。This API is not CLS-compliant.

Explicit(Decimal to Single) Explicit(Decimal to Single) Explicit(Decimal to Single) Explicit(Decimal to Single)

定义从 Decimal 到单精度浮点数的显式转换。Defines an explicit conversion of a Decimal to a single-precision floating-point number.

Explicit(Decimal to SByte) Explicit(Decimal to SByte) Explicit(Decimal to SByte) Explicit(Decimal to SByte)

定义从 Decimal 到 8 位有符号整数的显式转换。Defines an explicit conversion of a Decimal to an 8-bit signed integer.

此 API 不兼容 CLS。This API is not CLS-compliant.

Explicit(Decimal to UInt64) Explicit(Decimal to UInt64) Explicit(Decimal to UInt64) Explicit(Decimal to UInt64)

定义从 Decimal 到 64 位无符号整数的显式转换。Defines an explicit conversion of a Decimal to a 64-bit unsigned integer.

此 API 不兼容 CLS。This API is not CLS-compliant.

Explicit(Decimal to Int32) Explicit(Decimal to Int32) Explicit(Decimal to Int32) Explicit(Decimal to Int32)

定义从 Decimal 到 32 位有符号整数的显式转换。Defines an explicit conversion of a Decimal to a 32-bit signed integer.

Explicit(Decimal to Int16) Explicit(Decimal to Int16) Explicit(Decimal to Int16) Explicit(Decimal to Int16)

定义从 Decimal 到 16 位有符号整数的显式转换。Defines an explicit conversion of a Decimal to a 16-bit signed integer.

Explicit(Decimal to Double) Explicit(Decimal to Double) Explicit(Decimal to Double) Explicit(Decimal to Double)

定义从 Decimal 到双精度浮点数的显式转换。Defines an explicit conversion of a Decimal to a double-precision floating-point number.

Explicit(Decimal to Char) Explicit(Decimal to Char) Explicit(Decimal to Char) Explicit(Decimal to Char)

定义从 Unicode 字符到 Decimal 的显式转换。Defines an explicit conversion of a Decimal to a Unicode character.

Explicit(Decimal to Byte) Explicit(Decimal to Byte) Explicit(Decimal to Byte) Explicit(Decimal to Byte)

定义从 Decimal 到 8 位无符号整数的显式转换。Defines an explicit conversion of a Decimal to an 8-bit unsigned integer.

Explicit(Decimal to Int64) Explicit(Decimal to Int64) Explicit(Decimal to Int64) Explicit(Decimal to Int64)

定义从 Decimal 到 64 位有符号整数的显式转换。Defines an explicit conversion of a Decimal to a 64-bit signed integer.

GreaterThan(Decimal, Decimal) GreaterThan(Decimal, Decimal) GreaterThan(Decimal, Decimal) GreaterThan(Decimal, Decimal)

返回一个值,该值指示指定的 Decimal 是否大于另一个指定的 DecimalReturns a value indicating whether a specified Decimal is greater than another specified Decimal.

GreaterThanOrEqual(Decimal, Decimal) GreaterThanOrEqual(Decimal, Decimal) GreaterThanOrEqual(Decimal, Decimal) GreaterThanOrEqual(Decimal, Decimal)

返回一个值,该值指示指定的 Decimal 是否大于等于另一个指定的 DecimalReturns a value indicating whether a specified Decimal is greater than or equal to another specified Decimal.

Implicit(UInt32 to Decimal) Implicit(UInt32 to Decimal) Implicit(UInt32 to Decimal) Implicit(UInt32 to Decimal)

定义从 32 位无符号整数到 Decimal 的隐式转换。Defines an implicit conversion of a 32-bit unsigned integer to a Decimal.

此 API 不兼容 CLS。This API is not CLS-compliant.

Implicit(UInt16 to Decimal) Implicit(UInt16 to Decimal) Implicit(UInt16 to Decimal) Implicit(UInt16 to Decimal)

定义从 16 位无符号整数到 Decimal 的隐式转换。Defines an implicit conversion of a 16-bit unsigned integer to a Decimal.

此 API 不兼容 CLS。This API is not CLS-compliant.

Implicit(SByte to Decimal) Implicit(SByte to Decimal) Implicit(SByte to Decimal) Implicit(SByte to Decimal)

定义从 8 位有符号整数到 Decimal 值的隐式转换。Defines an implicit conversion of an 8-bit signed integer to a Decimal.

此 API 不兼容 CLS。This API is not CLS-compliant.

Implicit(Int64 to Decimal) Implicit(Int64 to Decimal) Implicit(Int64 to Decimal) Implicit(Int64 to Decimal)

定义从 64 位有符号整数到 Decimal 的隐式转换。Defines an implicit conversion of a 64-bit signed integer to a Decimal.

Implicit(Byte to Decimal) Implicit(Byte to Decimal) Implicit(Byte to Decimal) Implicit(Byte to Decimal)

定义从 8 位无符号整数到 Decimal 的隐式转换。Defines an implicit conversion of an 8-bit unsigned integer to a Decimal.

Implicit(Int16 to Decimal) Implicit(Int16 to Decimal) Implicit(Int16 to Decimal) Implicit(Int16 to Decimal)

定义从 16 位有符号整数到 Decimal 的隐式转换。Defines an implicit conversion of a 16-bit signed integer to a Decimal.

Implicit(Char to Decimal) Implicit(Char to Decimal) Implicit(Char to Decimal) Implicit(Char to Decimal)

定义从 Unicode 字符到 Decimal 的隐式转换。Defines an implicit conversion of a Unicode character to a Decimal.

Implicit(UInt64 to Decimal) Implicit(UInt64 to Decimal) Implicit(UInt64 to Decimal) Implicit(UInt64 to Decimal)

定义从 64 位无符号整数到 Decimal 的隐式转换。Defines an implicit conversion of a 64-bit unsigned integer to a Decimal.

此 API 不兼容 CLS。This API is not CLS-compliant.

Implicit(Int32 to Decimal) Implicit(Int32 to Decimal) Implicit(Int32 to Decimal) Implicit(Int32 to Decimal)

定义从 32 位有符号整数到 Decimal 的隐式转换。Defines an implicit conversion of a 32-bit signed integer to a Decimal.

Increment(Decimal) Increment(Decimal) Increment(Decimal) Increment(Decimal)

Decimal 操作数增加 1。Increments the Decimal operand by 1.

Inequality(Decimal, Decimal) Inequality(Decimal, Decimal) Inequality(Decimal, Decimal) Inequality(Decimal, Decimal)

返回一个值,该值指示两个 Decimal 对象是否具有不同的值。Returns a value that indicates whether two Decimal objects have different values.

LessThan(Decimal, Decimal) LessThan(Decimal, Decimal) LessThan(Decimal, Decimal) LessThan(Decimal, Decimal)

返回一个值,该值指示指定的 Decimal 是否小于另一个指定的 DecimalReturns a value indicating whether a specified Decimal is less than another specified Decimal.

LessThanOrEqual(Decimal, Decimal) LessThanOrEqual(Decimal, Decimal) LessThanOrEqual(Decimal, Decimal) LessThanOrEqual(Decimal, Decimal)

返回一个值,该值指示指定的 Decimal 是小于还是等于另一个指定的 DecimalReturns a value indicating whether a specified Decimal is less than or equal to another specified Decimal.

Modulus(Decimal, Decimal) Modulus(Decimal, Decimal) Modulus(Decimal, Decimal) Modulus(Decimal, Decimal)

返回两个指定 Decimal 值相除所得的余数。Returns the remainder resulting from dividing two specified Decimal values.

Multiply(Decimal, Decimal) Multiply(Decimal, Decimal) Multiply(Decimal, Decimal) Multiply(Decimal, Decimal)

两个指定的 Decimal 值相乘。Multiplies two specified Decimal values.

Subtraction(Decimal, Decimal) Subtraction(Decimal, Decimal) Subtraction(Decimal, Decimal) Subtraction(Decimal, Decimal)

将两个指定的 Decimal 值相减。Subtracts two specified Decimal values.

UnaryNegation(Decimal) UnaryNegation(Decimal) UnaryNegation(Decimal) UnaryNegation(Decimal)

对指定 Decimal 操作数的值求反。Negates the value of the specified Decimal operand.

UnaryPlus(Decimal) UnaryPlus(Decimal) UnaryPlus(Decimal) UnaryPlus(Decimal)

返回 Decimal 操作数的值(操作数符号不变)。Returns the value of the Decimal operand (the sign of the operand is unchanged).

显式界面实现

IComparable.CompareTo(Object) IComparable.CompareTo(Object) IComparable.CompareTo(Object) IComparable.CompareTo(Object)
IConvertible.GetTypeCode() IConvertible.GetTypeCode() IConvertible.GetTypeCode() IConvertible.GetTypeCode()
IConvertible.ToBoolean(IFormatProvider) IConvertible.ToBoolean(IFormatProvider) IConvertible.ToBoolean(IFormatProvider) IConvertible.ToBoolean(IFormatProvider)

有关此成员的说明,请参见 ToBoolean(IFormatProvider)For a description of this member, see ToBoolean(IFormatProvider).

IConvertible.ToByte(IFormatProvider) IConvertible.ToByte(IFormatProvider) IConvertible.ToByte(IFormatProvider) IConvertible.ToByte(IFormatProvider)

有关此成员的说明,请参见 ToByte(IFormatProvider)For a description of this member, see ToByte(IFormatProvider).

IConvertible.ToChar(IFormatProvider) IConvertible.ToChar(IFormatProvider) IConvertible.ToChar(IFormatProvider) IConvertible.ToChar(IFormatProvider)

不支持此转换。This conversion is not supported. 尝试使用此方法将引发 InvalidCastExceptionAttempting to use this method throws an InvalidCastException.

IConvertible.ToDateTime(IFormatProvider) IConvertible.ToDateTime(IFormatProvider) IConvertible.ToDateTime(IFormatProvider) IConvertible.ToDateTime(IFormatProvider)

不支持此转换。This conversion is not supported. 尝试使用此方法将引发 InvalidCastExceptionAttempting to use this method throws an InvalidCastException.

IConvertible.ToDecimal(IFormatProvider) IConvertible.ToDecimal(IFormatProvider) IConvertible.ToDecimal(IFormatProvider) IConvertible.ToDecimal(IFormatProvider)

有关此成员的说明,请参见 ToDecimal(IFormatProvider)For a description of this member, see ToDecimal(IFormatProvider).

IConvertible.ToDouble(IFormatProvider) IConvertible.ToDouble(IFormatProvider) IConvertible.ToDouble(IFormatProvider) IConvertible.ToDouble(IFormatProvider)

有关此成员的说明,请参见 ToDouble(IFormatProvider)For a description of this member, see ToDouble(IFormatProvider).

IConvertible.ToInt16(IFormatProvider) IConvertible.ToInt16(IFormatProvider) IConvertible.ToInt16(IFormatProvider) IConvertible.ToInt16(IFormatProvider)

有关此成员的说明,请参见 ToInt16(IFormatProvider)For a description of this member, see ToInt16(IFormatProvider).

IConvertible.ToInt32(IFormatProvider) IConvertible.ToInt32(IFormatProvider) IConvertible.ToInt32(IFormatProvider) IConvertible.ToInt32(IFormatProvider)

有关此成员的说明,请参见 ToInt32(IFormatProvider)For a description of this member, see ToInt32(IFormatProvider).

IConvertible.ToInt64(IFormatProvider) IConvertible.ToInt64(IFormatProvider) IConvertible.ToInt64(IFormatProvider) IConvertible.ToInt64(IFormatProvider)

有关此成员的说明,请参见 ToInt64(IFormatProvider)For a description of this member, see ToInt64(IFormatProvider).

IConvertible.ToSByte(IFormatProvider) IConvertible.ToSByte(IFormatProvider) IConvertible.ToSByte(IFormatProvider) IConvertible.ToSByte(IFormatProvider)

有关此成员的说明,请参见 ToSByte(IFormatProvider)For a description of this member, see ToSByte(IFormatProvider).

IConvertible.ToSingle(IFormatProvider) IConvertible.ToSingle(IFormatProvider) IConvertible.ToSingle(IFormatProvider) IConvertible.ToSingle(IFormatProvider)

有关此成员的说明,请参见 ToSingle(IFormatProvider)For a description of this member, see ToSingle(IFormatProvider).

IConvertible.ToType(Type, IFormatProvider) IConvertible.ToType(Type, IFormatProvider) IConvertible.ToType(Type, IFormatProvider) IConvertible.ToType(Type, IFormatProvider)

有关此成员的说明,请参见 ToType(Type, IFormatProvider)For a description of this member, see ToType(Type, IFormatProvider).

IConvertible.ToUInt16(IFormatProvider) IConvertible.ToUInt16(IFormatProvider) IConvertible.ToUInt16(IFormatProvider) IConvertible.ToUInt16(IFormatProvider)

有关此成员的说明,请参见 ToUInt16(IFormatProvider)For a description of this member, see ToUInt16(IFormatProvider).

IConvertible.ToUInt32(IFormatProvider) IConvertible.ToUInt32(IFormatProvider) IConvertible.ToUInt32(IFormatProvider) IConvertible.ToUInt32(IFormatProvider)

有关此成员的说明,请参见 ToInt32(IFormatProvider)For a description of this member, see ToInt32(IFormatProvider).

IConvertible.ToUInt64(IFormatProvider) IConvertible.ToUInt64(IFormatProvider) IConvertible.ToUInt64(IFormatProvider) IConvertible.ToUInt64(IFormatProvider)

有关此成员的说明,请参见 ToInt64(IFormatProvider)For a description of this member, see ToInt64(IFormatProvider).

IDeserializationCallback.OnDeserialization(Object) IDeserializationCallback.OnDeserialization(Object) IDeserializationCallback.OnDeserialization(Object) IDeserializationCallback.OnDeserialization(Object)

在对象的反序列化完成时运行。Runs when the deserialization of an object has been completed.

适用于

线程安全性

此类型的所有成员都是线程安全的。All members of this type are thread safe. 看似修改实例状态的成员实际上返回用新值初始化的新实例。Members that appear to modify instance state actually return a new instance initialized with the new value. 与任何其他类型一样,读取和写入包含此类型的实例的共享变量时,必须通过锁保护以保证线程安全。As with any other type, reading and writing to a shared variable that contains an instance of this type must be protected by a lock to guarantee thread safety.

另请参阅