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. 例如,下列程式碼會產生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

此類型提供將值轉換DecimalInt32 Int16 、、、UInt32Byte、、和UInt64值的方法。 UInt16 Int64 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為和來自SingleDouble值的方法。 DecimalThe Decimal type also provides methods that convert Decimal values to and from Single and Double values. DecimalSingle或的轉換是縮小轉換,可能會失去精確度,而不是轉換值大小的相關資訊。DoubleConversions 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)

將包含 OLE Automation 貨幣值的指定 64 位元帶正負號整數,轉換為對等的 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 值乘以負一的乘積。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)

使用指定的樣式和特定文化特性格式,將數字的字串表示轉換為其對等的 DecimalConverts 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)

使用指定的特定文化特性格式資訊,將數字的字串表示轉換為其對等的 DecimalConverts 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)

將數字的字串表示,轉換為其相等的 DecimalConverts 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 Automation 貨幣值,這個值包含在 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)

使用指定的樣式和特定文化特性格式,將數字的字串表示轉換為其對等的 DecimalConverts 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)

將數字的字串表示,轉換為其相等的 DecimalConverts 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 運算元減一。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.

此應用程式開發介面不符合 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.

此應用程式開發介面不符合 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.

此應用程式開發介面不符合 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.

此應用程式開發介面不符合 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)

定義從 Decimal 到 Unicode 字元的明確轉換。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.

此應用程式開發介面不符合 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.

此應用程式開發介面不符合 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.

此應用程式開發介面不符合 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.

此應用程式開發介面不符合 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.

另請參閱