Decimal 结构
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示十进制浮点数。
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
- 继承
- 属性
- 实现
-
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 ( (-296 到96) / 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 值转换为 和 转换Decimal值Single的方法。 从 Decimal 到 Single 或 Double 的转换会缩小转换范围,这些转换可能会失去精度,但不会提供有关已转换值的量级的信息。 转换不会引发异常。
如果转换的结果不能表示为 Decimal,则从 Single 或 Double 到 Decimal 的转换将引发OverflowException异常。
对十进制值执行操作
类型 Decimal 支持标准数学运算,例如加、减、除、乘和一元求反。 还可以通过调用 GetBits 方法直接处理值的二进制表示形式Decimal。
若要比较两个 Decimal 值,可以使用标准数值比较运算符,也可以调用 CompareTo 或 Equals 方法。
还可以调用 类的成员 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 之间的数字,表示小数位数。 |
方法
运算符
显式接口实现
适用于
线程安全性
此类型的所有成员都是线程安全的。 看起来修改实例状态的成员实际上返回使用新值初始化的新实例。 与任何其他类型一样,读取和写入包含此类型的实例的共享变量必须受到锁的保护,以确保线程安全。