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值类型表示十进制数字范围从-79228162514264337593543950335 到 + 79228162514264337593543950335。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. 例如,下面的代码生成而不是 1 0.9999999999999999999999999999 的结果。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.

二进制表示形式Decimal1 位符号、 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)),其中的 (296为-1)等同于MinValue,并 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值与SByteInt16Int32Int64ByteUInt16UInt32,和UInt64值。This 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值到和从SingleDouble值。The Decimal type also provides methods that convert Decimal values to and from Single and Double values. 从转换DecimalSingleDouble收缩转换可能会丢失精度,但不是有关信息的量值的转换后的值。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.

从转换SingleDoubleDecimal引发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值,可以使用标准数值比较运算符,也可以调用CompareToEquals方法。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.

另请参阅