Decimal 结构

定义

表示十进制浮点数。

public value class System::Decimal : IComparable, IComparable<System::Decimal>, IConvertible, IEquatable<System::Decimal>, IFormattable
public value class System::Decimal : IComparable, IComparable<System::Decimal>, IConvertible, IEquatable<System::Decimal>, IFormattable, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public value class System::Decimal : IComparable, IComparable<System::Decimal>, IConvertible, IEquatable<System::Decimal>, ISpanFormattable, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public value class System::Decimal : IComparable<System::Decimal>, IConvertible, IEquatable<System::Decimal>, IParsable<System::Decimal>, ISpanParsable<System::Decimal>, System::Numerics::IAdditionOperators<System::Decimal, System::Decimal, System::Decimal>, System::Numerics::IAdditiveIdentity<System::Decimal, System::Decimal>, System::Numerics::IComparisonOperators<System::Decimal, System::Decimal, bool>, System::Numerics::IDecrementOperators<System::Decimal>, System::Numerics::IDivisionOperators<System::Decimal, System::Decimal, System::Decimal>, System::Numerics::IEqualityOperators<System::Decimal, System::Decimal, bool>, System::Numerics::IFloatingPoint<System::Decimal>, System::Numerics::IFloatingPointConstants<System::Decimal>, System::Numerics::IIncrementOperators<System::Decimal>, System::Numerics::IMinMaxValue<System::Decimal>, System::Numerics::IModulusOperators<System::Decimal, System::Decimal, System::Decimal>, System::Numerics::IMultiplicativeIdentity<System::Decimal, System::Decimal>, System::Numerics::IMultiplyOperators<System::Decimal, System::Decimal, System::Decimal>, System::Numerics::INumber<System::Decimal>, System::Numerics::INumberBase<System::Decimal>, System::Numerics::ISignedNumber<System::Decimal>, System::Numerics::ISubtractionOperators<System::Decimal, System::Decimal, System::Decimal>, System::Numerics::IUnaryNegationOperators<System::Decimal, System::Decimal>, System::Numerics::IUnaryPlusOperators<System::Decimal, System::Decimal>, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public value class System::Decimal : IComparable<System::Decimal>, IConvertible, IEquatable<System::Decimal>, IParsable<System::Decimal>, ISpanParsable<System::Decimal>, IUtf8SpanFormattable, IUtf8SpanParsable<System::Decimal>, System::Numerics::IAdditionOperators<System::Decimal, System::Decimal, System::Decimal>, System::Numerics::IAdditiveIdentity<System::Decimal, System::Decimal>, System::Numerics::IComparisonOperators<System::Decimal, System::Decimal, bool>, System::Numerics::IDecrementOperators<System::Decimal>, System::Numerics::IDivisionOperators<System::Decimal, System::Decimal, System::Decimal>, System::Numerics::IEqualityOperators<System::Decimal, System::Decimal, bool>, System::Numerics::IFloatingPoint<System::Decimal>, System::Numerics::IFloatingPointConstants<System::Decimal>, System::Numerics::IIncrementOperators<System::Decimal>, System::Numerics::IMinMaxValue<System::Decimal>, System::Numerics::IModulusOperators<System::Decimal, System::Decimal, System::Decimal>, System::Numerics::IMultiplicativeIdentity<System::Decimal, System::Decimal>, System::Numerics::IMultiplyOperators<System::Decimal, System::Decimal, System::Decimal>, System::Numerics::INumber<System::Decimal>, System::Numerics::INumberBase<System::Decimal>, System::Numerics::ISignedNumber<System::Decimal>, System::Numerics::ISubtractionOperators<System::Decimal, System::Decimal, System::Decimal>, System::Numerics::IUnaryNegationOperators<System::Decimal, System::Decimal>, System::Numerics::IUnaryPlusOperators<System::Decimal, System::Decimal>, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public value class System::Decimal : IComparable, IComparable<System::Decimal>, IConvertible, IEquatable<System::Decimal>, IFormattable, System::Runtime::Serialization::IDeserializationCallback
public value class System::Decimal : IComparable, IConvertible, IFormattable
public value class System::Decimal : IComparable, IComparable<System::Decimal>, IEquatable<System::Decimal>, IFormattable
public struct Decimal : IComparable, IComparable<decimal>, IConvertible, IEquatable<decimal>, IFormattable
public readonly struct Decimal : IComparable, IComparable<decimal>, IConvertible, IEquatable<decimal>, IFormattable, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
public readonly struct Decimal : IComparable, IComparable<decimal>, IConvertible, IEquatable<decimal>, ISpanFormattable, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
public readonly struct Decimal : IComparable<decimal>, IConvertible, IEquatable<decimal>, IParsable<decimal>, ISpanParsable<decimal>, System.Numerics.IAdditionOperators<decimal,decimal,decimal>, System.Numerics.IAdditiveIdentity<decimal,decimal>, System.Numerics.IComparisonOperators<decimal,decimal,bool>, System.Numerics.IDecrementOperators<decimal>, System.Numerics.IDivisionOperators<decimal,decimal,decimal>, System.Numerics.IEqualityOperators<decimal,decimal,bool>, System.Numerics.IFloatingPoint<decimal>, System.Numerics.IFloatingPointConstants<decimal>, System.Numerics.IIncrementOperators<decimal>, System.Numerics.IMinMaxValue<decimal>, System.Numerics.IModulusOperators<decimal,decimal,decimal>, System.Numerics.IMultiplicativeIdentity<decimal,decimal>, System.Numerics.IMultiplyOperators<decimal,decimal,decimal>, System.Numerics.INumber<decimal>, System.Numerics.INumberBase<decimal>, System.Numerics.ISignedNumber<decimal>, System.Numerics.ISubtractionOperators<decimal,decimal,decimal>, System.Numerics.IUnaryNegationOperators<decimal,decimal>, System.Numerics.IUnaryPlusOperators<decimal,decimal>, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
public readonly struct Decimal : IComparable<decimal>, IConvertible, IEquatable<decimal>, IParsable<decimal>, ISpanParsable<decimal>, IUtf8SpanFormattable, IUtf8SpanParsable<decimal>, System.Numerics.IAdditionOperators<decimal,decimal,decimal>, System.Numerics.IAdditiveIdentity<decimal,decimal>, System.Numerics.IComparisonOperators<decimal,decimal,bool>, System.Numerics.IDecrementOperators<decimal>, System.Numerics.IDivisionOperators<decimal,decimal,decimal>, System.Numerics.IEqualityOperators<decimal,decimal,bool>, System.Numerics.IFloatingPoint<decimal>, System.Numerics.IFloatingPointConstants<decimal>, System.Numerics.IIncrementOperators<decimal>, System.Numerics.IMinMaxValue<decimal>, System.Numerics.IModulusOperators<decimal,decimal,decimal>, System.Numerics.IMultiplicativeIdentity<decimal,decimal>, System.Numerics.IMultiplyOperators<decimal,decimal,decimal>, System.Numerics.INumber<decimal>, System.Numerics.INumberBase<decimal>, System.Numerics.ISignedNumber<decimal>, System.Numerics.ISubtractionOperators<decimal,decimal,decimal>, System.Numerics.IUnaryNegationOperators<decimal,decimal>, System.Numerics.IUnaryPlusOperators<decimal,decimal>, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
public struct Decimal : IComparable, IComparable<decimal>, IConvertible, IEquatable<decimal>, IFormattable, System.Runtime.Serialization.IDeserializationCallback
public readonly struct Decimal : IComparable, IComparable<decimal>, IConvertible, IEquatable<decimal>, IFormattable, System.Runtime.Serialization.IDeserializationCallback
[System.Serializable]
public struct Decimal : IComparable, IConvertible, IFormattable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct Decimal : IComparable, IComparable<decimal>, IConvertible, IEquatable<decimal>, IFormattable
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public struct Decimal : IComparable, IComparable<decimal>, IConvertible, IEquatable<decimal>, IFormattable, System.Runtime.Serialization.IDeserializationCallback
public struct Decimal : IComparable, IComparable<decimal>, IEquatable<decimal>, IFormattable
type decimal = struct
    interface IConvertible
    interface IFormattable
type decimal = struct
    interface IConvertible
    interface IFormattable
    interface IDeserializationCallback
    interface ISerializable
type decimal = struct
    interface IConvertible
    interface ISpanFormattable
    interface IFormattable
    interface IDeserializationCallback
    interface ISerializable
type decimal = struct
    interface IConvertible
    interface IFormattable
    interface IParsable<decimal>
    interface ISpanFormattable
    interface ISpanParsable<decimal>
    interface IAdditionOperators<decimal, decimal, decimal>
    interface IAdditiveIdentity<decimal, decimal>
    interface IComparisonOperators<decimal, decimal, bool>
    interface IEqualityOperators<decimal, decimal, bool>
    interface IDecrementOperators<decimal>
    interface IDivisionOperators<decimal, decimal, decimal>
    interface IFloatingPoint<decimal>
    interface IFloatingPointConstants<decimal>
    interface INumberBase<decimal>
    interface IIncrementOperators<decimal>
    interface IMultiplicativeIdentity<decimal, decimal>
    interface IMultiplyOperators<decimal, decimal, decimal>
    interface ISubtractionOperators<decimal, decimal, decimal>
    interface IUnaryNegationOperators<decimal, decimal>
    interface IUnaryPlusOperators<decimal, decimal>
    interface IModulusOperators<decimal, decimal, decimal>
    interface INumber<decimal>
    interface ISignedNumber<decimal>
    interface IMinMaxValue<decimal>
    interface IDeserializationCallback
    interface ISerializable
type decimal = struct
    interface IConvertible
    interface IFormattable
    interface IParsable<decimal>
    interface ISpanFormattable
    interface ISpanParsable<decimal>
    interface IAdditionOperators<decimal, decimal, decimal>
    interface IAdditiveIdentity<decimal, decimal>
    interface IComparisonOperators<decimal, decimal, bool>
    interface IEqualityOperators<decimal, decimal, bool>
    interface IDecrementOperators<decimal>
    interface IDivisionOperators<decimal, decimal, decimal>
    interface IFloatingPoint<decimal>
    interface IFloatingPointConstants<decimal>
    interface INumberBase<decimal>
    interface IIncrementOperators<decimal>
    interface IMultiplicativeIdentity<decimal, decimal>
    interface IMultiplyOperators<decimal, decimal, decimal>
    interface ISubtractionOperators<decimal, decimal, decimal>
    interface IUnaryNegationOperators<decimal, decimal>
    interface IUnaryPlusOperators<decimal, decimal>
    interface IUtf8SpanParsable<decimal>
    interface IModulusOperators<decimal, decimal, decimal>
    interface INumber<decimal>
    interface ISignedNumber<decimal>
    interface IMinMaxValue<decimal>
    interface IDeserializationCallback
    interface ISerializable
    interface IUtf8SpanFormattable
type decimal = struct
    interface IConvertible
    interface IFormattable
    interface IDeserializationCallback
[<System.Serializable>]
type decimal = struct
    interface IFormattable
    interface IConvertible
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type decimal = struct
    interface IFormattable
    interface IConvertible
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type decimal = struct
    interface IFormattable
    interface IConvertible
    interface IDeserializationCallback
type decimal = struct
    interface IFormattable
Public Structure Decimal
Implements IComparable, IComparable(Of Decimal), IConvertible, IEquatable(Of Decimal), IFormattable
Public Structure Decimal
Implements IComparable, IComparable(Of Decimal), IConvertible, IDeserializationCallback, IEquatable(Of Decimal), IFormattable, ISerializable
Public Structure Decimal
Implements IComparable, IComparable(Of Decimal), IConvertible, IDeserializationCallback, IEquatable(Of Decimal), ISerializable, ISpanFormattable
Public Structure Decimal
Implements IAdditionOperators(Of Decimal, Decimal, Decimal), IAdditiveIdentity(Of Decimal, Decimal), IComparable(Of Decimal), IComparisonOperators(Of Decimal, Decimal, Boolean), IConvertible, IDecrementOperators(Of Decimal), IDeserializationCallback, IDivisionOperators(Of Decimal, Decimal, Decimal), IEqualityOperators(Of Decimal, Decimal, Boolean), IEquatable(Of Decimal), IFloatingPoint(Of Decimal), IFloatingPointConstants(Of Decimal), IIncrementOperators(Of Decimal), IMinMaxValue(Of Decimal), IModulusOperators(Of Decimal, Decimal, Decimal), IMultiplicativeIdentity(Of Decimal, Decimal), IMultiplyOperators(Of Decimal, Decimal, Decimal), INumber(Of Decimal), INumberBase(Of Decimal), IParsable(Of Decimal), ISerializable, ISignedNumber(Of Decimal), ISpanParsable(Of Decimal), ISubtractionOperators(Of Decimal, Decimal, Decimal), IUnaryNegationOperators(Of Decimal, Decimal), IUnaryPlusOperators(Of Decimal, Decimal)
Public Structure Decimal
Implements IAdditionOperators(Of Decimal, Decimal, Decimal), IAdditiveIdentity(Of Decimal, Decimal), IComparable(Of Decimal), IComparisonOperators(Of Decimal, Decimal, Boolean), IConvertible, IDecrementOperators(Of Decimal), IDeserializationCallback, IDivisionOperators(Of Decimal, Decimal, Decimal), IEqualityOperators(Of Decimal, Decimal, Boolean), IEquatable(Of Decimal), IFloatingPoint(Of Decimal), IFloatingPointConstants(Of Decimal), IIncrementOperators(Of Decimal), IMinMaxValue(Of Decimal), IModulusOperators(Of Decimal, Decimal, Decimal), IMultiplicativeIdentity(Of Decimal, Decimal), IMultiplyOperators(Of Decimal, Decimal, Decimal), INumber(Of Decimal), INumberBase(Of Decimal), IParsable(Of Decimal), ISerializable, ISignedNumber(Of Decimal), ISpanParsable(Of Decimal), ISubtractionOperators(Of Decimal, Decimal, Decimal), IUnaryNegationOperators(Of Decimal, Decimal), IUnaryPlusOperators(Of Decimal, Decimal), IUtf8SpanFormattable, IUtf8SpanParsable(Of Decimal)
Public Structure Decimal
Implements IComparable, IComparable(Of Decimal), IConvertible, IDeserializationCallback, IEquatable(Of Decimal), IFormattable
Public Structure Decimal
Implements IComparable, IConvertible, IFormattable
Public Structure Decimal
Implements IComparable, IComparable(Of Decimal), IEquatable(Of Decimal), IFormattable
继承
Decimal
属性
实现
IComparable IComparable<Decimal> IConvertible IEquatable<Decimal> IFormattable IDeserializationCallback ISerializable ISpanFormattable IComparable<TSelf> IEquatable<TSelf> IParsable<Decimal> IParsable<TSelf> ISpanParsable<Decimal> ISpanParsable<TSelf> IAdditionOperators<Decimal,Decimal,Decimal> IAdditionOperators<TSelf,TSelf,TSelf> IAdditiveIdentity<Decimal,Decimal> IAdditiveIdentity<TSelf,TSelf> IComparisonOperators<Decimal,Decimal,Boolean> IComparisonOperators<TSelf,TSelf,Boolean> IDecrementOperators<Decimal> IDecrementOperators<TSelf> IDivisionOperators<Decimal,Decimal,Decimal> IDivisionOperators<TSelf,TSelf,TSelf> IEqualityOperators<Decimal,Decimal,Boolean> IEqualityOperators<TSelf,TOther,TResult> IEqualityOperators<TSelf,TSelf,Boolean> IFloatingPoint<Decimal> IFloatingPointConstants<Decimal> IFloatingPointConstants<TSelf> IIncrementOperators<Decimal> IIncrementOperators<TSelf> IMinMaxValue<Decimal> IModulusOperators<Decimal,Decimal,Decimal> IModulusOperators<TSelf,TSelf,TSelf> IMultiplicativeIdentity<Decimal,Decimal> IMultiplicativeIdentity<TSelf,TSelf> IMultiplyOperators<Decimal,Decimal,Decimal> IMultiplyOperators<TSelf,TSelf,TSelf> INumber<Decimal> INumber<TSelf> INumberBase<Decimal> INumberBase<TSelf> ISignedNumber<Decimal> ISignedNumber<TSelf> ISubtractionOperators<Decimal,Decimal,Decimal> ISubtractionOperators<TSelf,TSelf,TSelf> IUnaryNegationOperators<Decimal,Decimal> IUnaryNegationOperators<TSelf,TSelf> IUnaryPlusOperators<Decimal,Decimal> IUnaryPlusOperators<TSelf,TSelf> IUtf8SpanFormattable IUtf8SpanParsable<Decimal> IUtf8SpanParsable<TSelf>

示例

以下代码示例演示了 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.
type PiggyBank() =
    let mutable myFortune = 0m

    member _.AddPenny() =
        myFortune <- Decimal.Add(myFortune, 0.01m)

    member _.Capacity =
        Decimal.MaxValue

    member _.Dollars =
        Decimal.Floor myFortune

    member _.Cents =
        Decimal.Subtract(myFortune, Decimal.Floor myFortune)

    override _.ToString() =
        $"{myFortune: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 之间的十进制数字。 Decimal 的默认值为 0。 值 Decimal 类型适用于需要大量有效整数和小数位数且没有舍入误差的财务计算。 Decimal 类型仍需要舍入,但它最大限度地减少了因舍入而导致的错误。 相反,它最大限度地减少了因舍入而导致的错误。 例如,下面的代码生成 0.9999999999999999999999999999 的结果,而不是 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);
let dividend = Decimal.One
let divisor = 3m
// The following displays 0.9999999999999999999999999999 to the console
printfn $"{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 方法时,结果不会丢失精度,如以下代码所示。

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));
let dividend = Decimal.One
let divisor = 3m
// The following displays 1.00 to the console
printfn $"{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)和一个比例因子(指示将数值的整数和小数部分分隔开)的浮点位置组成。

值的二进制表示形式 Decimal 是 128 位,由 96 位整数组成,以及一组 32 位标志,表示诸如用于指定小数小数部分的符号和缩放因子等内容。 因此,值的二进制表示形式 Decimal ( (-29696) / 10 (0 到 28) ) ,其中 - (296-1) 等于 MinValue,296-1 等于 MaxValue。 有关值的二进制表示形式 Decimal 和示例的详细信息,请参阅 Decimal(Int32[]) 构造函数和 GetBits 方法。

缩放因子还会保留数字中的任何 Decimal 尾随零。 尾随零不会影响算术或比较运算中数字的值 Decimal 。 但是,如果应用了适当的格式字符串, ToString 则 方法可能会显示尾随零。

转换注意事项

此类型提供将值与 、、 Int64ByteUInt16Int16Int32UInt32和 值SByte进行转换Decimal的方法。UInt64 从这些整型类型到 Decimal 的转换是扩大转换,永远不会丢失信息或引发异常。

Decimal 到任何整型类型的转换都是将值舍入 Decimal 到最接近的整数值与零的转换范围缩小。 某些语言(如 C#)也支持将值转换为DecimalChar值。 如果这些转换的结果无法在目标类型中表示,则会引发异常 OverflowException

类型Decimal还提供将值与 和 Double 值转换为 和 转换DecimalSingle的方法。 从 DecimalSingleDouble 的转换会缩小转换范围,这些转换可能会失去精度,但不会提供有关已转换值的量级的信息。 转换不会引发异常。

如果转换的结果不能表示为 Decimal,则从 SingleDoubleDecimal 的转换将引发OverflowException异常。

对十进制值执行操作

类型 Decimal 支持标准数学运算,例如加、减、除、乘和一元求反。 还可以通过调用 GetBits 方法直接处理值的二进制表示形式Decimal

若要比较两个 Decimal 值,可以使用标准数值比较运算符,也可以调用 CompareToEquals 方法。

还可以调用 类的成员 Math 来执行各种数值运算,包括获取数字的绝对值、确定两 Decimal 个值的最大值或最小值、获取数字的符号以及舍入数字。

构造函数

Decimal(Double)

Decimal 的新实例初始化为指定的双精度浮点数的值。

Decimal(Int32)

Decimal 的新实例初始化为指定的 32 位有符号整数的值。

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

用指定实例构成部分的参数来初始化 Decimal 的新实例。

Decimal(Int32[])

Decimal 的新实例初始化为以二进制表示的、包含在指定数组中的十进制值。

Decimal(Int64)

Decimal 的新实例初始化为指定的 64 位有符号整数的值。

Decimal(ReadOnlySpan<Int32>)

Decimal 的新实例初始化为以二进制表示的、包含在指定范围中的十进制值。

Decimal(Single)

Decimal 的新实例初始化为指定的单精度浮点数的值。

Decimal(UInt32)

Decimal 的新实例初始化为指定的 32 位无符号整数的值。

Decimal(UInt64)

Decimal 的新实例初始化为指定的 64 位无符号整数的值。

字段

MaxValue

表示 Decimal 的最大可能值。 该字段是常数且为只读。

MinusOne

表示数字负一 (-1)。

MinValue

表示 Decimal 的最小可能值。 该字段是常数且为只读。

One

表示数字一 (1)。

Zero

表示数字零 (0)。

属性

Scale

获取小数的缩放因子,该小数是一个介于 0 到 28 之间的数字,表示小数位数。

方法

Abs(Decimal)

计算值的绝对值。

Add(Decimal, Decimal)

将两个指定的 Decimal 值相加。

Ceiling(Decimal)

返回大于或等于指定的十进制数的最小整数值。

Clamp(Decimal, Decimal, Decimal)

将值固定为非独占最小值和最大值。

Compare(Decimal, Decimal)

比较两个指定的 Decimal 值。

CompareTo(Decimal)

将此实例与指定的 Decimal 对象进行比较并返回一个对二者的相对值的比较。

CompareTo(Object)

将此实例与指定对象进行比较并返回一个对二者的相对值的比较。

CopySign(Decimal, Decimal)

将值的符号复制到另一个值的符号。

CreateChecked<TOther>(TOther)

从值创建当前类型的实例,对超出当前类型的可表示范围的任何值引发溢出异常。

CreateSaturating<TOther>(TOther)

从值创建当前类型的实例,使当前类型的可表示范围之外的任何值饱和。

CreateTruncating<TOther>(TOther)

从值创建当前类型的实例,截断当前类型的可表示范围之外的任何值。

Divide(Decimal, Decimal)

将两个指定的 Decimal 值相除。

Equals(Decimal)

返回一个值,该值指示此实例和指定的 Decimal 对象是否表示相同的值。

Equals(Decimal, Decimal)

返回一个值,该值指示 Decimal 的两个指定实例是否表示同一个值。

Equals(Object)

返回一个值,该值指示此实例和指定的 Object 是否表示相同的类型和值。

Floor(Decimal)

将指定的 Decimal 数字向负无穷方向舍入为最接近的整数。

FromOACurrency(Int64)

将指定的 64 位有符号整数(它包含 OLE 自动化货币值)转换为等效的 Decimal 值。

GetBits(Decimal)

Decimal 的指定实例的值转换为其等效的二进制表示形式。

GetBits(Decimal, Span<Int32>)

Decimal 的指定实例的值转换为其等效的二进制表示形式。

GetHashCode()

返回此实例的哈希代码。

GetTypeCode()

返回值类型 TypeCodeDecimal

IsCanonical(Decimal)

确定值是否在其规范表示形式中。

IsEvenInteger(Decimal)

确定值是否表示偶数整数。

IsInteger(Decimal)

确定值是否表示整数。

IsNegative(Decimal)

确定值是否为负值。

IsOddInteger(Decimal)

确定值是否表示奇数整数。

IsPositive(Decimal)

确定值是否为正值。

Max(Decimal, Decimal)

将两个值与计算进行比较,这两个值更大。

MaxMagnitude(Decimal, Decimal)

将两个值与计算进行比较,这两个值更大。

Min(Decimal, Decimal)

将两个值与较小的计算进行比较。

MinMagnitude(Decimal, Decimal)

将两个值与较小的计算进行比较。

Multiply(Decimal, Decimal)

两个指定的 Decimal 值相乘。

Negate(Decimal)

返回指定的 Decimal 值乘以 -1 的结果。

Parse(ReadOnlySpan<Byte>, IFormatProvider)

将 UTF-8 字符范围分析为值。

Parse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider)

将 UTF-8 字符范围分析为值。

Parse(ReadOnlySpan<Char>, IFormatProvider)

将字符范围分析为值。

Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider)

使用指定样式和区域性特定格式将数字的范围表示形式转换为其 Decimal 等效项。

Parse(String)

将数字的字符串表示形式转换为它的等效 Decimal 表示形式。

Parse(String, IFormatProvider)

使用指定的区域性特定格式信息将数字的字符串表示形式转换为其 Decimal 等效项。

Parse(String, NumberStyles)

将指定样式的数字的字符串表示形式转换为它的等效 Decimal

Parse(String, NumberStyles, IFormatProvider)

使用指定样式和区域性特定格式将数字的字符串表示形式转换为其 Decimal 等效项。

Remainder(Decimal, Decimal)

计算两个 Decimal 值相除后的余数。

Round(Decimal)

将小数值舍入到最接近的整数。

Round(Decimal, Int32)

Decimal 值舍入到指定的小数位数。

Round(Decimal, Int32, MidpointRounding)

使用指定的舍入策略将小数点值舍入到指定的精度。

Round(Decimal, MidpointRounding)

使用指定的舍入策略将十进制值舍入为整数。

Sign(Decimal)

计算值的符号。

Subtract(Decimal, Decimal)

从一个 Decimal 值中减去指定的另一个值。

ToByte(Decimal)

将指定的 Decimal 的值转换为等效的 8 位无符号整数。

ToDouble(Decimal)

将指定的 Decimal 的值转换为等效的双精度浮点数。

ToInt16(Decimal)

将指定的 Decimal 值转换为等效的 16 位有符号整数。

ToInt32(Decimal)

将指定的 Decimal 值转换为等效的 32 位有符号整数。

ToInt64(Decimal)

将指定的 Decimal 值转换为等效的 64 位有符号整数。

ToOACurrency(Decimal)

将指定的 Decimal 值转换为等效的 OLE 自动化货币值,该值包含在一个 64 位有符号整数中。

ToSByte(Decimal)

将指定的 Decimal 值转换为等效的 8 位有符号整数。

ToSingle(Decimal)

将指定的 Decimal 的值转换为等效的单精度浮点数。

ToString()

将此实例的数值转换为其等效的字符串表示形式。

ToString(IFormatProvider)

使用指定的区域性特定格式信息,将此实例的数值转换为它的等效字符串表示形式。

ToString(String)

使用指定的格式,将此实例的数值转换为它的等效字符串表示形式。

ToString(String, IFormatProvider)

使用指定的格式和区域性特定格式信息,将此实例的数值转换为它的等效字符串表示形式。

ToUInt16(Decimal)

将指定的 Decimal 的值转换为等效的 16 位无符号整数。

ToUInt32(Decimal)

将指定的 Decimal 的值转换为等效的 32 位无符号整数。

ToUInt64(Decimal)

将指定的 Decimal 的值转换为等效的 64 位无符号整数。

Truncate(Decimal)

返回指定的 Decimal 的整数位,所有小数位均被放弃。

TryFormat(Span<Byte>, Int32, ReadOnlySpan<Char>, IFormatProvider)

尝试将当前实例的值格式化为 UTF-8,将其设置为提供的字节范围。

TryFormat(Span<Char>, Int32, ReadOnlySpan<Char>, IFormatProvider)

尝试将当前十进制实例的值的格式设置为提供的字符范围。

TryGetBits(Decimal, Span<Int32>, Int32)

尝试将 Decimal 的指定实例的值转换为其等效的二进制表示形式。

TryParse(ReadOnlySpan<Byte>, Decimal)

尝试将包含数字字符串表示形式的 UTF-8 字符范围转换为其带符号十进制等效项。

TryParse(ReadOnlySpan<Byte>, IFormatProvider, Decimal)

尝试将 UTF-8 字符范围解析为值。

TryParse(ReadOnlySpan<Byte>, NumberStyles, IFormatProvider, Decimal)

尝试将 UTF-8 字符范围解析为值。

TryParse(ReadOnlySpan<Char>, Decimal)

使用指定样式和区域性特定格式将数字的范围表示形式转换为其 Decimal 等效项。 一个指示转换是否成功的返回值。

TryParse(ReadOnlySpan<Char>, IFormatProvider, Decimal)

尝试将字符范围解析为值。

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

使用指定样式和区域性特定格式将数字的范围表示形式转换为其 Decimal 等效项。 一个指示转换是否成功的返回值。

TryParse(String, Decimal)

将数字的字符串表示形式转换为它的等效 Decimal 表示形式。 一个指示转换是否成功的返回值。

TryParse(String, IFormatProvider, Decimal)

尝试将字符串解析为值。

TryParse(String, NumberStyles, IFormatProvider, Decimal)

使用指定样式和区域性特定格式将数字的字符串表示形式转换为其 Decimal 等效项。 一个指示转换是否成功的返回值。

运算符

Addition(Decimal, Decimal)

将两个指定的 Decimal 值相加。

Decrement(Decimal)

Decimal 操作数减 1。

Division(Decimal, Decimal)

将两个指定的 Decimal 值相除。

Equality(Decimal, Decimal)

返回一个值,该值指示两个 Decimal 值是否相等。

Explicit(Decimal to Byte)

定义从 Decimal 到 8 位无符号整数的显式转换。

Explicit(Decimal to Char)

定义从 Unicode 字符到 Decimal 的显式转换。

Explicit(Decimal to Double)

定义从 Decimal 到双精度浮点数的显式转换。

Explicit(Decimal to Int16)

定义从 Decimal 到 16 位有符号整数的显式转换。

Explicit(Decimal to Int32)

定义从 Decimal 到 32 位有符号整数的显式转换。

Explicit(Decimal to Int64)

定义从 Decimal 到 64 位有符号整数的显式转换。

Explicit(Decimal to SByte)

定义从 Decimal 到 8 位有符号整数的显式转换。

此 API 不兼容 CLS。

Explicit(Decimal to Single)

定义从 Decimal 到单精度浮点数的显式转换。

Explicit(Decimal to UInt16)

定义从 Decimal 到 16 位无符号整数的显式转换。

此 API 不兼容 CLS。

Explicit(Decimal to UInt32)

定义从 Decimal 到 32 位无符号整数的显式转换。

此 API 不兼容 CLS。

Explicit(Decimal to UInt64)

定义从 Decimal 到 64 位无符号整数的显式转换。

此 API 不兼容 CLS。

Explicit(Double to Decimal)

定义从双精度浮点数到 Decimal 的显式转换。

Explicit(Single to Decimal)

定义从单精度浮点数到 Decimal 的显式转换。

GreaterThan(Decimal, Decimal)

返回一个值,该值指示指定的 Decimal 是否大于另一个指定的 Decimal

GreaterThanOrEqual(Decimal, Decimal)

返回一个值,该值指示指定的 Decimal 是否大于等于另一个指定的 Decimal

Implicit(Byte to Decimal)

定义从 8 位无符号整数到 Decimal 的隐式转换。

Implicit(Char to Decimal)

定义从 Unicode 字符到 Decimal 的隐式转换。

Implicit(Int16 to Decimal)

定义从 16 位有符号整数到 Decimal 的隐式转换。

Implicit(Int32 to Decimal)

定义从 32 位有符号整数到 Decimal 的隐式转换。

Implicit(Int64 to Decimal)

定义从 64 位有符号整数到 Decimal 的隐式转换。

Implicit(SByte to Decimal)

定义从 8 位有符号整数到 Decimal 值的隐式转换。

此 API 不兼容 CLS。

Implicit(UInt16 to Decimal)

定义从 16 位无符号整数到 Decimal 的隐式转换。

此 API 不兼容 CLS。

Implicit(UInt32 to Decimal)

定义从 32 位无符号整数到 Decimal 的隐式转换。

此 API 不兼容 CLS。

Implicit(UInt64 to Decimal)

定义从 64 位无符号整数到 Decimal 的隐式转换。

此 API 不兼容 CLS。

Increment(Decimal)

Decimal 操作数增加 1。

Inequality(Decimal, Decimal)

返回一个值,该值指示两个 Decimal 对象是否具有不同的值。

LessThan(Decimal, Decimal)

返回一个值,该值指示指定的 Decimal 是否小于另一个指定的 Decimal

LessThanOrEqual(Decimal, Decimal)

返回一个值,该值指示指定的 Decimal 是小于还是等于另一个指定的 Decimal

Modulus(Decimal, Decimal)

返回两个指定 Decimal 值相除所得的余数。

Multiply(Decimal, Decimal)

两个指定的 Decimal 值相乘。

Subtraction(Decimal, Decimal)

将两个指定的 Decimal 值相减。

UnaryNegation(Decimal)

对指定 Decimal 操作数的值求反。

UnaryPlus(Decimal)

返回 Decimal 操作数的值(操作数符号不变)。

显式接口实现

IAdditiveIdentity<Decimal,Decimal>.AdditiveIdentity

获取当前类型的累加标识。

IComparable.CompareTo(Object)

将当前实例与同一类型的另一个对象进行比较,并返回一个整数,该整数指示当前实例在排序顺序中的位置是位于另一个对象之前、之后还是与其位置相同。

IConvertible.GetTypeCode()

返回此实例的 TypeCode

IConvertible.ToBoolean(IFormatProvider)

有关此成员的说明,请参见 ToBoolean(IFormatProvider)

IConvertible.ToByte(IFormatProvider)

有关此成员的说明,请参见 ToByte(IFormatProvider)

IConvertible.ToChar(IFormatProvider)

不支持此转换。 尝试使用此方法将引发 InvalidCastException

IConvertible.ToDateTime(IFormatProvider)

不支持此转换。 尝试使用此方法将引发 InvalidCastException

IConvertible.ToDecimal(IFormatProvider)

有关此成员的说明,请参见 ToDecimal(IFormatProvider)

IConvertible.ToDouble(IFormatProvider)

有关此成员的说明,请参见 ToDouble(IFormatProvider)

IConvertible.ToInt16(IFormatProvider)

有关此成员的说明,请参见 ToInt16(IFormatProvider)

IConvertible.ToInt32(IFormatProvider)

有关此成员的说明,请参见 ToInt32(IFormatProvider)

IConvertible.ToInt64(IFormatProvider)

有关此成员的说明,请参见 ToInt64(IFormatProvider)

IConvertible.ToSByte(IFormatProvider)

有关此成员的说明,请参见 ToSByte(IFormatProvider)

IConvertible.ToSingle(IFormatProvider)

有关此成员的说明,请参见 ToSingle(IFormatProvider)

IConvertible.ToType(Type, IFormatProvider)

有关此成员的说明,请参见 ToType(Type, IFormatProvider)

IConvertible.ToUInt16(IFormatProvider)

有关此成员的说明,请参见 ToUInt16(IFormatProvider)

IConvertible.ToUInt32(IFormatProvider)

有关此成员的说明,请参见 ToInt32(IFormatProvider)

IConvertible.ToUInt64(IFormatProvider)

有关此成员的说明,请参见 ToInt64(IFormatProvider)

IDeserializationCallback.OnDeserialization(Object)

在对象的反序列化完成时运行。

IFloatingPoint<Decimal>.GetExponentByteCount()

获取将作为 的一部分写入的 TryWriteExponentLittleEndian(Span<Byte>, Int32)字节数。

IFloatingPoint<Decimal>.GetExponentShortestBitLength()

获取当前指数的最短两个补补表示形式的长度(以位为单位)。

IFloatingPoint<Decimal>.GetSignificandBitLength()

获取当前有效值的长度(以位为单位)。

IFloatingPoint<Decimal>.GetSignificandByteCount()

获取将作为 的一部分写入的 TryWriteSignificandLittleEndian(Span<Byte>, Int32)字节数。

IFloatingPoint<Decimal>.TryWriteExponentBigEndian(Span<Byte>, Int32)

尝试以大端格式将当前指数写入给定范围。

IFloatingPoint<Decimal>.TryWriteExponentLittleEndian(Span<Byte>, Int32)

尝试以 little endian 格式将当前指数写入给定范围。

IFloatingPoint<Decimal>.TryWriteSignificandBigEndian(Span<Byte>, Int32)

尝试以 big-endian 格式将当前有效值写入给定范围。

IFloatingPoint<Decimal>.TryWriteSignificandLittleEndian(Span<Byte>, Int32)

尝试以 little-endian 格式将当前有效值写入给定范围。

IFloatingPointConstants<Decimal>.E

获取数学常量 e

IFloatingPointConstants<Decimal>.Pi

获取数学常量 pi

IFloatingPointConstants<Decimal>.Tau

获取数学常量 tau

IMinMaxValue<Decimal>.MaxValue

获取当前类型的最大值。

IMinMaxValue<Decimal>.MinValue

获取当前类型的最小值。

IMultiplicativeIdentity<Decimal,Decimal>.MultiplicativeIdentity

获取当前类型的乘法标识。

INumber<Decimal>.MaxNumber(Decimal, Decimal)

比较两个值以计算较大值,如果输入为 , NaN则返回另一个值。

INumber<Decimal>.MinNumber(Decimal, Decimal)

将两个值进行比较以计算较小的值,如果输入为 NaN,则返回另一个值。

INumberBase<Decimal>.IsComplexNumber(Decimal)

确定值是否表示复数。

INumberBase<Decimal>.IsFinite(Decimal)

确定值是否为有限值。

INumberBase<Decimal>.IsImaginaryNumber(Decimal)

确定值是否表示纯虚数。

INumberBase<Decimal>.IsInfinity(Decimal)

确定值是否无限。

INumberBase<Decimal>.IsNaN(Decimal)

确定值是否为 NaN。

INumberBase<Decimal>.IsNegativeInfinity(Decimal)

确定值是否为负无穷大。

INumberBase<Decimal>.IsNormal(Decimal)

确定值是否正常。

INumberBase<Decimal>.IsPositiveInfinity(Decimal)

确定值是否为正无穷大。

INumberBase<Decimal>.IsRealNumber(Decimal)

确定值是否表示实数。

INumberBase<Decimal>.IsSubnormal(Decimal)

确定值是否为非正常值。

INumberBase<Decimal>.IsZero(Decimal)

确定值是否为零。

INumberBase<Decimal>.MaxMagnitudeNumber(Decimal, Decimal)

将两个值进行比较,以计算其具有更大的数量级并返回另一个值(如果输入为 NaN)。

INumberBase<Decimal>.MinMagnitudeNumber(Decimal, Decimal)

将两个值进行比较,以计算其数量级较小并返回另一个值(如果输入为 NaN)。

INumberBase<Decimal>.One

获取类型的值 1

INumberBase<Decimal>.Radix

获取类型的基数。

INumberBase<Decimal>.TryConvertFromChecked<TOther>(TOther, Decimal)

表示十进制浮点数。

INumberBase<Decimal>.TryConvertFromSaturating<TOther>(TOther, Decimal)

表示十进制浮点数。

INumberBase<Decimal>.TryConvertFromTruncating<TOther>(TOther, Decimal)

表示十进制浮点数。

INumberBase<Decimal>.TryConvertToChecked<TOther>(Decimal, TOther)

尝试将当前类型的实例转换为另一种类型,从而引发超出当前类型可表示范围的任何值的溢出异常。

INumberBase<Decimal>.TryConvertToSaturating<TOther>(Decimal, TOther)

尝试将当前类型的实例转换为另一种类型,使超出当前类型可表示范围的任何值饱和。

INumberBase<Decimal>.TryConvertToTruncating<TOther>(Decimal, TOther)

尝试将当前类型的实例转换为另一种类型,截断当前类型可表示范围之外的任何值。

INumberBase<Decimal>.Zero

获取类型的值 0

ISerializable.GetObjectData(SerializationInfo, StreamingContext)

使用将目标对象序列化所需的数据填充 SerializationInfo

ISignedNumber<Decimal>.NegativeOne

获取类型的值 -1

适用于

线程安全性

此类型的所有成员都是线程安全的。 看起来修改实例状态的成员实际上返回使用新值初始化的新实例。 与任何其他类型一样,读取和写入包含此类型的实例的共享变量必须受到锁的保护,以确保线程安全。

另请参阅