System.Decimal Structure

public struct Decimal: IComparable, IFormattable, IComparable<Decimal>, IEquatable<Decimal>

Base Types

Object
  ValueType
    Decimal

This type implements IFormattable, IComparable, System.IComparable<System.Decimal>, and System.IEquatable<System.Decimal>.

Assembly

mscorlib

Library

ExtendedNumerics

Summary

Represents a floating-point decimal data type with at least 28 significant digits, suitable for financial and commercial calculations.

Description

The Decimal type can represent values with at least 28 significant digits. The Decimal data type is ideally suited to financial calculations that require a large number of significant digits and no round-off errors.

The Decimal type shall represent values in at least the range -79228162514264337593543950335 to 79228162514264337593543950335, and having scale f such that 0 <= f <= at least 28.

A Decimal value occupies 128 bits; however, its representation is unspecified (see note below).

The result of an operation on values of type Decimal is that which would result from calculating an exact result (preserving scale, as defined for each operator) and then rounding to fit the representation. That is, results are exact to at least 28 digits, but not necessarily to more than 28 decimal places. A zero result has a sign of 0.

Results are rounded to the nearest representable value, and, when a result is equally close to two representable values, to the value that has an even number in the least significant digit position (banker's rounding).

The default initial value of an instance of type Decimal is zero with a scale of zero.

[Note: Unlike the Single and Double data types, decimal fractional numbers such as 0.1 can be represented exactly in the Decimal representation. In the Single and Double representations, such numbers are often infinite fractions, making those representations prone to round-off errors.

Further, the Decimal representation preserves scale, so that 1.23 + 1.27 will give the answer 2.50, not 2.5.

]

If a Decimal arithmetic operation produces a value that is too small for the Decimal format after rounding, the result of the operation is zero. If a Decimal arithmetic operation produces a result that is too large for the Decimal format, a OverflowException is thrown.

[Note: The Decimal class implements implicit conversions from the SByte, Byte, Int16, UInt16, Int32, UInt32, Int64, and UInt64 types to Decimal. These implicit conversions never lose information and never throw exceptions. The Decimal class also implements explicit conversions from Decimal to Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, and UInt64. These explicit conversions round the Decimal value towards zero to the nearest integer, and then convert that integer to the destination type. A OverflowException is thrown if the result is not within the range of the destination type.

The Decimal class provides narrowing conversions to and from the Single and Double types. A conversion from Decimal to Single or Double can lose precision. If the value being converted is not within the range of the destination type, a OverflowException is thrown. A conversion from Single or Double to Decimal throws a OverflowException if the value is not within the range of the Decimal type.

]

[Note: Although different implementations of Decimal can have different representations, interchange of a decimal value within the range of the internal format can still be achieved by converting it to a string, exporting it, and then converting it back to internal format.

]

[Note: In Version 1 of this standard, the representation of Decimal was well-defined, as follows.

When considered as an array of four Int32s, it contains the following four elements:

Index 0 (bits 0-31) contains the low-order 32 bits of the decimal's coefficient.

Index 1 (bits 32-63) contains the middle 32 bits of the decimal's coefficient.

Index 2 (bits 64-95) contains the high-order 32 bits of the decimal's coefficient.

Index 3 (bits 96-127) contains the sign bit and scale, as follows:

Bit PositionsName
0-15(None.)
16-23 Scale
24-30 (None.)
31 Sign
In order to allow alternate representations (such as in the update to the IEC floating-point standard, IEC-60559, currently in preparation), the representation has been made unspecified.

]

See Also

System Namespace

Members

Decimal Constructors

Decimal(int) Constructor
Decimal(uint) Constructor
Decimal(long) Constructor
Decimal(ulong) Constructor
Decimal(float) Constructor
Decimal(double) Constructor
Decimal(int[]) Constructor

Decimal Methods

Decimal.Add Method
Decimal.Compare Method
Decimal.CompareTo(System.Decimal) Method
Decimal.CompareTo(System.Object) Method
Decimal.Divide Method
Decimal.Equals(System.Decimal) Method
Decimal.Equals(System.Object) Method
Decimal.Equals(System.Decimal, System.Decimal) Method
Decimal.Floor Method
Decimal.GetBits Method
Decimal.GetHashCode Method
Decimal.Multiply Method
Decimal.Negate Method
Decimal.Parse(System.String) Method
Decimal.Parse(System.String, System.Globalization.NumberStyles) Method
Decimal.Parse(System.String, System.IFormatProvider) Method
Decimal.Parse(System.String, System.Globalization.NumberStyles, System.IFormatProvider) Method
Decimal.Remainder Method
Decimal.Round Method
Decimal.Subtract Method
Decimal.ToString(System.String) Method
Decimal.ToString() Method
Decimal.ToString(System.String, System.IFormatProvider) Method
Decimal.ToString(System.IFormatProvider) Method
Decimal.Truncate Method
Decimal.op_Addition Method
Decimal.op_Decrement Method
Decimal.op_Division Method
Decimal.op_Equality Method
double Decimal.op_Explicit(System.Decimal) Method
float Decimal.op_Explicit(System.Decimal) Method
ulong Decimal.op_Explicit(System.Decimal) Method
long Decimal.op_Explicit(System.Decimal) Method
uint Decimal.op_Explicit(System.Decimal) Method
int Decimal.op_Explicit(System.Decimal) Method
sbyte Decimal.op_Explicit(System.Decimal) Method
byte Decimal.op_Explicit(System.Decimal) Method
System.Decimal Decimal.op_Explicit(double) Method
System.Decimal Decimal.op_Explicit(float) Method
char Decimal.op_Explicit(System.Decimal) Method
ushort Decimal.op_Explicit(System.Decimal) Method
short Decimal.op_Explicit(System.Decimal) Method
Decimal.op_GreaterThan Method
Decimal.op_GreaterThanOrEqual Method
System.Decimal Decimal.op_Implicit(byte) Method
System.Decimal Decimal.op_Implicit(sbyte) Method
System.Decimal Decimal.op_Implicit(short) Method
System.Decimal Decimal.op_Implicit(ushort) Method
System.Decimal Decimal.op_Implicit(char) Method
System.Decimal Decimal.op_Implicit(int) Method
System.Decimal Decimal.op_Implicit(uint) Method
System.Decimal Decimal.op_Implicit(long) Method
System.Decimal Decimal.op_Implicit(ulong) Method
Decimal.op_Increment Method
Decimal.op_Inequality Method
Decimal.op_LessThan Method
Decimal.op_LessThanOrEqual Method
Decimal.op_Modulus Method
Decimal.op_Multiply Method
Decimal.op_Subtraction Method
Decimal.op_UnaryNegation Method
Decimal.op_UnaryPlus Method

Decimal Fields

Decimal.MaxValue Field
Decimal.MinValue Field
Decimal.MinusOne Field
Decimal.One Field
Decimal.Zero Field


Decimal(int) Constructor

public Decimal(int value);

Summary

Constructs and initializes a new Decimal value.

Parameters

value
The Int32 value used to initialize the new Decimal.

Description

This constructor initializes the new Decimal to the value specified by value. The scale of the new Decimal is 0.

See Also

System.Decimal Structure, System Namespace

Decimal(uint) Constructor

public Decimal(uint value);

Summary

Constructs and initializes a new Decimal value.

Parameters

value
The UInt32 value used to initialize the new Decimal.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use the Decimal(Int64) constructor.

This constructor initializes the new Decimal to the value specified by value. The scale of the new Decimal is 0.

Attributes

CLSCompliantAttribute(false)

See Also

System.Decimal Structure, System Namespace

Decimal(long) Constructor

public Decimal(long value);

Summary

Constructs and initializes a new Decimal value.

Parameters

value
The Int64 value used to initialize the new Decimal.

Description

This constructor initializes the new Decimal to the value specified by value. The scale of the new Decimal is 0.

See Also

System.Decimal Structure, System Namespace

Decimal(ulong) Constructor

public Decimal(ulong value);

Summary

Constructs and initializes a new Decimal value.

Parameters

value
The UInt64 value used to initialize the new Decimal.

Description

This constructor initializes the new Decimal to the value specified by value. The scale of the new Decimal is 0.

This member is not CLS-compliant. For a CLS-compliant alternative, use the Decimal(Int64) constructor.

Attributes

CLSCompliantAttribute(false)

See Also

System.Decimal Structure, System Namespace

Decimal(float) Constructor

public Decimal(float value);

Summary

Constructs and initializes a new Decimal value.

Parameters

value
The Single value used to initialize the new Decimal.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is one of the following:

greater than System.Decimal.MaxValue

less than System.Decimal.MinValue

equal to System.Single.NaN, but the Decimal representation does not support NaNs.

equal to System.Single.PositiveInfinity, but the Decimal representation does not support infinities.

equal to System.Single.NegativeInfinity, but the Decimal representation does not support infinities.

Description

This constructor initializes the new Decimal to the value specified by value. This constructor rounds value to 7 significant digits using banker's rounding. The scale of the new Decimal is the same as that produced by System.Decimal.Parse( value.ToString()) .

See Also

System.Decimal Structure, System Namespace

Decimal(double) Constructor

public Decimal(double value);

Summary

Constructs and initializes a new Decimal value.

Parameters

value
The Double value used to initialize the new Decimal.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is one of the following:

greater than System.Decimal.MaxValue

less than System.Decimal.MinValue

equal to System.Double.NaN, but the Decimal representation does not support NaNs.

equal to System.Double.PositiveInfinity, but the Decimal representation does not support infinities.

equal to System.Double.NegativeInfinity, but the Decimal representation does not support infinities.

Description

This constructor initializes the new Decimal to the value specified by value. This constructor rounds value to 15 significant digits using banker's rounding. The scale of the new Decimal is the same as that produced by System.Decimal.Parse( value.ToString()) .

See Also

System.Decimal Structure, System Namespace

Decimal(int[]) Constructor

public Decimal(int[] bits);

Summary

Constructs and initializes a new Decimal value.

Parameters

bits
An array of four Int32 containing an unspecified 128-bit representation of a Decimal in its raw form.

Exceptions

Exception TypeCondition
ArgumentNullExceptionbits is a null reference.
ArgumentExceptionbits does not contain four elements.

Description

This constructor initializes the new Decimal to the value represented by the elements of bits .

[Note: A numeric value can have several possible binary representations; they are numerically equal but have different scales. Also, the bit representation differentiates between -0, 0.00, and 0; these are all treated as 0 in operations, and any zero result will have a sign of 0.]

The format of bits is the same as that returned by System.Decimal.GetBits(System.Decimal) .

See Also

System.Decimal Structure, System Namespace

Decimal.Add Method

public static decimal Add(decimal d1, decimal d2);

Summary

Adds two Decimal values together.

Parameters

d1
The first addend.
d2
The second addend.

Return Value

A Decimal containing the sum of d1 and d2. The scale of the result, before any rounding, is the larger of the scales of d1 and d2. For example, 1.1 + 2.22 gives 3.32, and 2.50 + 1 gives 3.50.

Exceptions

Exception TypeCondition
OverflowExceptionThe sum of d1 and d2 is less than System.Decimal.MinValue or greater than System.Decimal.MaxValue.

See Also

System.Decimal Structure, System Namespace

Decimal.Compare Method

public static int Compare(decimal d1, decimal d2);

Summary

Compares the values of two Decimal values and returns sort order information.

Parameters

d1
The first value to compare.
d2
The second value to compare.

Return Value

The return value is a negative number, zero, or a positive number reflecting the sort order of d1 as compared to d2. Trailing zero digits in the fractional part of are ignored. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value. Each comparison compares the numerical values of d1 and d2.

Return Value Meaning
Any negative numberd1&lt; d2
Zerod1 == d2
A positive numberd1&gt;d2

See Also

System.Decimal Structure, System Namespace

Decimal.CompareTo(System.Decimal) Method

public int CompareTo(decimal value);

Summary

Returns the sort order of the current instance compared to the specified Decimal.

Parameters

value
The Decimal to compare to the current instance.

Return Value

The return value is a negative number, zero, or a positive number reflecting the sort order of the current instance as compared to value. Trailing zero digits in the fractional part of the current instance and value. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:

Return ValueDescription
A negative numberCurrent instance < value.
ZeroCurrent instance == value.
A positive numbercurrent instance > value.

Description

[Note: This method is implemented to support the System.IComparable<Decimal> interface.]

See Also

System.Decimal Structure, System Namespace

Decimal.CompareTo(System.Object) Method

public int CompareTo(object value);

Summary

Returns the sort order of the current instance compared to the specified Object .

Parameters

value
The Object to compare to the current instance.

Return Value

The return value is a negative number, zero, or a positive number reflecting the sort order of the current instance as compared to value. Trailing zero digits in the fractional part of the current instance and value. For non-zero return values, the exact value returned by this method is unspecified. The following table defines the return value:

Return ValueDescription
A negative numberCurrent instance < value.
ZeroCurrent instance == value.
A positive numbercurrent instance > value, or value is a null reference.

Exceptions

Exception TypeCondition
ArgumentExceptionvalue is not a Decimal and is not a null reference.

Description

[Note: This method is implemented to support the IComparable interface.]

See Also

System.Decimal Structure, System Namespace

Decimal.Divide Method

public static valuetype System.Decimal Divide(valuetype System.Decimal d1, valuetype System.Decimal d2);

Summary

Divides the value of one Decimal by another.

Parameters

d1
The dividend.
d2
The divisor.

Return Value

A Decimal containing the result of dividing d1 by d2. The scale of the result, before any rounding, is the closest scale to the preferred scale which will preserve a result equal to the exact result. The preferred scale is the scale of d1 less the scale of d2. For example, 2.20 / 2 gives 1.10.

Exceptions

Exception TypeCondition
DivideByZeroExceptiond2 is zero.
OverflowExceptionThe result is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.

See Also

System.Decimal Structure, System Namespace

Decimal.Equals(System.Decimal) Method

public override bool Equals(decimal value);

Summary

Determines whether the current instance and the specified Decimal have the same value. Trailing zero digits in the fractional part are ignored.

Parameters

value
The Decimal to compare to the current instance.

Return Value

true if value is numerically equal to (has the same value as) the current instance; otherwise, false .

Description

[Note: This method is implemented to support the System.IEquatable<Decimal> interface.]

See Also

System.Decimal Structure, System Namespace

Decimal.Equals(System.Object) Method

public override bool Equals(object value);

Summary

Determines whether the current instance and the specified Object have the same type and value. Trailing zero digits in the fractional part are ignored.

Parameters

value
The Object to compare to the current instance.

Return Value

true if value has the same type and is numerically equal to (has the same value as) the current instance. If value is a null reference or is not an instance of Decimal, returns false .

Description

[Note: This method overrides System.Object.Equals(System.Object).]

See Also

System.Decimal Structure, System Namespace

Decimal.Equals(System.Decimal, System.Decimal) Method

public static bool Equals(decimal d1, decimal d2);

Summary

Determines whether two Decimal values have the same value. Trailing zero digits in the fractional part are ignored.

Parameters

d1
The first Decimal to compare.
d2
The second Decimal to compare.

Return Value

true if d1 and d2 are numerically equal (have the same value), otherwise false .

See Also

System.Decimal Structure, System Namespace

Decimal.Floor Method

public static decimal Floor(decimal d);

Summary

Rounds a Decimal value to the closest integer towards negative infinity.

Parameters

d
The Decimal to round downward.

Return Value

A Decimal value v such that v is an integer and d - 1 < v <= d . The scale of the result will be zero.

Example

The following example demonstrates the System.Decimal.Floor(System.Decimal) method.

using System;
class DecimalTest {
 public static void Main() {
   Console.WriteLine("floor {0} is {1}", 3.14159m, Decimal.Floor(3.14159m));
   Console.WriteLine("floor {0} is {1}", -3.9m, Decimal.Floor(-3.9m));
   Console.WriteLine("floor {0} is {1}", 3.0m, Decimal.Floor(3.0m));
 }
}
The output is

floor 3.14159 is 3

floor -3.9 is -4

floor 3.0 is 3

See Also

System.Decimal Structure, System Namespace

Decimal.GetBits Method

public static int[] GetBits(decimal d);

Summary

Returns a binary representation of the specified Decimal value.

Parameters

d
The Decimal value for which a binary representation is returned.

Return Value

An array of four Int32 containing an unspecified 128-bit representation of a Decimal in its raw form.

Description

The format of the bits in the 4-element array returned is the same as that used by the bits parameter to System.Decimal.Decimal(System.Int32) .

A numeric value can have several possible binary representations; they are numerically equal but have different scales. Also, the bit representation differentiates between -0, 0.00, and 0; these are all treated as 0 in operations, and any zero result will have a sign of 0.

Example

The following example demonstrates the different representations of 1.00 and 1.

using System;
public class Class1  {
    public static void Print (int [] bs) {
        foreach (int b in bs) {
            Console.Write (b+" ");
        }
    }
public static void Main () {
   decimal d = 1.00m;
    decimal d1 = 1;
    Console.Write (d);
    Console.Write (" - bits: "); 
    Print (decimal.GetBits(d));
    Console.WriteLine();
    Console.Write (d1);
    Console.Write (" - bits: "); 
    Print (decimal.GetBits(d1));
    Console.WriteLine();
    Console.WriteLine ("d1.CompareTo(d) == {0}", d1.CompareTo(d));
    Console.WriteLine ("d1 == d {0}", d1 == d);
}
}
   

See Also

System.Decimal Structure, System Namespace

Decimal.GetHashCode Method

public override int GetHashCode();

Summary

Generates a hash code for the current instance. Trailing zero digits in the fractional part are ignored.

Return Value

A Int32 containing the hash code for this instance.

Description

The algorithm used to generate the hash code value is unspecified.

[Note: This method overrides System.Object.GetHashCode.]

See Also

System.Decimal Structure, System Namespace

Decimal.Multiply Method

public static decimal Multiply(decimal d1, decimal d2);

Summary

Returns the result of multiplying two Decimal values.

Parameters

d1
The multiplier.
d2
The multiplicand.

Return Value

The result of multiplying d1 and d2 . The scale of the result, before any rounding, is the sum of the scales of d1 and d2.

For example, 123 x 3 gives 369, and 2.2 x 1.35 gives 2.970.

Exceptions

Exception TypeCondition
OverflowExceptionThe result is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.

See Also

System.Decimal Structure, System Namespace

Decimal.Negate Method

public static decimal Negate(decimal d);

Summary

Returns the result of multiplying a Decimal value by negative one.

Parameters

d
The value to negate.

Return Value

The negated value of d. If d is zero then zero is returned (with 0 sign); otherwise the scale of the result is the same as the scale of d .

See Also

System.Decimal Structure, System Namespace

Decimal.Parse(System.String) Method

public static valuetype System.Decimal Parse(string s);

Summary

Returns the specified String converted to a Decimal value.

Parameters

s
A String containing the value to convert. The string is interpreted using the System.Globalization.NumberStyles.Number style, preserving scale.

Return Value

The Decimal value obtained from s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct format.
OverflowExceptions represents a number greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.

Description

This version of System.Decimal.Parse(System.String) is equivalent to System.Decimal.Parse(System.String) (s , System.Globalization.NumberStyles.Number , null ).

The string s is parsed using the formatting information in a NumberFormatInfo initialized for the current system culture. [Note: For more information, see System.Globalization.NumberFormatInfo.CurrentInfo .]

If necessary, the value of s is rounded using banker's rounding. Any scale apparent in the string s is preserved unless the value is rounded. If the value is zero, the sign will be 0. Hence the string "2.900" will be parsed to form the decimal with sign 0, coefficient 2900, and scale 3.

Example

The following example demonstrates the System.Decimal.Parse(System.String) method.

using System;
using System.Globalization;
class DecimalParseClass {
  public static void Main() {
    string s1 = " -1.001  ";
    string s2 = "+1,000,111.99";     
    string s3 = "2.900";
    Console.WriteLine("String: {0} (decimal) {1}",s1,Decimal.Parse(s1));
    Console.WriteLine("String: {0} (decimal) {1}",s2,Decimal.Parse(s2));
    Console.WriteLine("String: {0} (decimal) {1}",s3,Decimal.Parse(s3));
  }
}
The output is

String: -1.001 (decimal) -1.001

String: +1,000,111.99 (decimal) 1000111.99

String: 2.900 (decimal) 2.900

See Also

System.Decimal Structure, System Namespace

Decimal.Parse(System.String, System.Globalization.NumberStyles) Method

public static valuetype System.Decimal Parse(string s, NumberStyles style);

Summary

Returns the specified String converted to a Decimal value.

Parameters

s
A String containing the value to convert. The string is interpreted using the style specified by style , preserving scale.
style
Zero or more NumberStyles values that specify the style of s. Specify multiple values for style using the bitwise OR operator. If style is a null reference, the string is interpreted using the System.Globalization.NumberStyles.Number style.

Return Value

The Decimal value obtained from s .

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct style.
OverflowExceptions represents a number greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.

Description

This version of System.Decimal.Parse(System.String) is equivalent to System.Decimal.Parse(System.String) (s, style , null ).

The string s is parsed using the formatting information in a NumberFormatInfo initialized for the current system culture. [Note: For more information, see System.Globalization.NumberFormatInfo.CurrentInfo .]

If necessary, the value of s is rounded using banker's rounding.

Example

The following example demonstrates supplying NumberStyles values to the System.Decimal.Parse(System.String) method to allow for a symbol separating groups of digits, and a decimal separator. This example uses the symbols from the U.S. English culture, namely a comma and a decimal point.

using System;
using System.Globalization;
class DecimalParseClass {
public static void Main() {
 string s = "1,000,111.99"; 
 NumberStyles ns = NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint;
 decimal d = Decimal.Parse(s,ns);
 Console.WriteLine("{0} parsed to decimal {1}",s,d);
}
}
The output is

1,000,111.99 parsed to decimal 1000111.99

See Also

System.Decimal Structure, System Namespace

Decimal.Parse(System.String, System.IFormatProvider) Method

public static decimal Parse(string s, IFormatProvider provider);

Summary

Returns the specified String converted to a Decimal value.

Parameters

s
A String containing the value to convert. The String is interpreted using the System.Globalization.NumberStyles.Number style, preserving scale.
provider
A IFormatProvider that supplies a NumberFormatInfo containing culture-specific formatting information about s.

Return Value

The Decimal value obtained from s .

Exceptions

Exception TypeCondition
FormatExceptions is not in the correct style.
OverflowExceptions represents a number greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.
ArgumentNullExceptions is a null reference.

Description

This version of System.Decimal.Parse(System.String) is equivalent to System.Decimal.Parse(System.String) (s, System.Globalization.NumberStyles.Number , provider ).

The string s is parsed using the culture-specific formatting information from the NumberFormatInfo instance supplied by provider. If provider is null or a NumberFormatInfo cannot be obtained from provider, the formatting information for the current system culture is used.

If necessary, the value of s is rounded using banker's rounding. Any scale apparent in the string s is preserved unless the value is rounded. If the value is zero, the sign scale will be 0. Hence the string "2.900" will be parsed to form the decimal with sign 0, coefficient 2900, and scale 3.

Example

The following example demonstrates supplying a IFormatProvider to the System.Decimal.Parse(System.String) method to allow a decimal point, and commas separating groups of digits.

using System;
using System.Globalization;
class DecimalParseClass {
public static void Main() {
 string s = "1,000,111.99"; 
 //Get the default formatting symbols.
 NumberFormatInfo nfi = new NumberFormatInfo();
 // Default group separator is ','
 // Default decimal separator is '.'
 decimal d = Decimal.Parse(s,nfi);
 Console.WriteLine("{0} parsed to decimal {1}",s,d);
}
}
The output is

1,000,111.99 parsed to decimal 1000111.99

See Also

System.Decimal Structure, System Namespace

Decimal.Parse(System.String, System.Globalization.NumberStyles, System.IFormatProvider) Method

public static decimal Parse(string s, NumberStyles style, IFormatProvider provider);

Summary

Returns the specified String converted to a Decimal value.

Parameters

s
A String containing the value to convert. The string is interpreted using the style specified by style , preserving scale.
style
Zero or more NumberStyles values that specify the style of s. Specify multiple values for style using the bitwise OR operator. If style is a null reference, the string is interpreted using the System.Globalization.NumberStyles.Number style.
provider
A IFormatProvider that supplies a NumberFormatInfo containing culture-specific formatting information about s.

Return Value

The Decimal value obtained from s .

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.

FormatExceptions is not in the correct style.
OverflowExceptions represents a number greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.

Description

The string s is parsed using the culture-specific formatting information from the NumberFormatInfo instance supplied by provider. If provider is null or if a NumberFormatInfo cannot be obtained from provider, the formatting information for the current system culture is used.

If necessary, the value of s is rounded using banker's rounding.

Example

The following example demonstrates supplying NumberStyles values and a IFormatProvider to the System.Decimal.Parse(System.String) method to allow colons separating groups of digits, and a decimal point.

using System;
using System.Globalization;
class DecimalParseClass {
public static void Main() {
 string s = "1:000:111.99"; 
 NumberStyles ns = NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint;
 NumberFormatInfo nfi = new NumberFormatInfo();
 //Change the format info to separate digit groups using a colon.
 nfi.NumberGroupSeparator = ":";
 decimal d = Decimal.Parse(s,ns,nfi);
 Console.WriteLine("{0} parsed to decimal {1}",s,d);
}
}
The output is

1:000:111.99 parsed to decimal 1000111.99

See Also

System.Decimal Structure, System Namespace

Decimal.Remainder Method

public static decimal Remainder(decimal d1, decimal d2);

Summary

Computes the remainder after dividing two Decimal values.

Parameters

d1
The dividend.
d2
The divisor.

Return Value

The remainder after dividing d1 by d2 to give an integer result. The sign of the result, if non-zero, is the same as the sign of d1, and the scale of the result is the larger of the scales of d1 and d2.

For example, -10 % 3 gives -1, and 3.6 % 1.3 gives 1.0 (where % indicates the remainder operation).

Exceptions

Exception TypeCondition
DivideByZeroExceptiond2 is zero.
OverflowExceptiond1 divided by d2 is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.

See Also

System.Decimal Structure, System Namespace

Decimal.Round Method

public static decimal Round(decimal d, int decimals);

Summary

Rounds a Decimal value to a specified number of decimal places.

Parameters

d
The Decimal to round.
decimals
The number of decimal places to round to. 0 <= decimals <= 28.

Return Value

The Decimal result of rounding d to decimals decimal places.

Exceptions

Exception TypeCondition
ArgumentOutOfRangeExceptiondecimals is not between 0 and 28, inclusive.

Description

When d is exactly half way between two rounded values, the result is the rounded value that has an even digit in the rightmost decimal position. For example, when rounded to two decimals, the value 2.345 becomes 2.34 and the value 2.355 becomes 2.36. [Note: This process is known as rounding half towards even, or banker's rounding.]

The scale of the result will be the smaller of decimals and the scale of d.

[Note: The scale of d is never increased, so System.Decimal.Round(System.Decimal,System.Int32) cannot cause overflow.]

Example

The following example demonstrates the System.Decimal.Round(System.Decimal,System.Int32) method.

using System;
class MyClass {
public static void Main() {
 decimal d1 = 2.5m;
 decimal d2 = 3.5m;
 decimal d3 = 2.98765432m;
 decimal d4 = 2.18765432m;
 Console.WriteLine("Rounding to 0 places...");
 Console.WriteLine("round {0} = {1}",d1, Decimal.Round(d1,0));
 Console.WriteLine("round {0} = {1}",d2, Decimal.Round(d2,0));
 Console.WriteLine("round {0} = {1}",d3, Decimal.Round(d3,0));
 Console.WriteLine("round {0} = {1}",d4, Decimal.Round(d4,0));
 Console.WriteLine("Rounding to 2 places...");
 Console.WriteLine("round {0} = {1}",d1, Decimal.Round(d1,2));
 Console.WriteLine("round {0} = {1}",d2, Decimal.Round(d2,2));
 Console.WriteLine("round {0} = {1}",d3, Decimal.Round(d3,2));
 Console.WriteLine("round {0} = {1}",d4, Decimal.Round(d4,2));
}
}
The output is

Rounding to 0 places...

round 2.5 = 2

round 3.5 = 4

round 2.98765432 = 3

round 2.18765432 = 2

Rounding to 2 places...

round 2.5 = 2.5

round 3.5 = 3.5

round 2.98765432 = 2.99

round 2.18765432 = 2.19

See Also

System.Decimal Structure, System Namespace

Decimal.Subtract Method

public static decimal Subtract(decimal d1, decimal d2);

Summary

Subtracts one Decimal value from another.

Parameters

d1
The left-side operand.
d2
The right-side operand.

Return Value

A Decimal containing the result of subtracting d2 from d1 . The scale of the result, before any rounding, is the larger of the scales of d1 and d2.

For example, 1.1 - 2.22 gives -1.12, and 2.50 - 1 gives 1.50.

Exceptions

Exception TypeCondition
OverflowExceptionThe result is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.

See Also

System.Decimal Structure, System Namespace

Decimal.ToString(System.String) Method

public string ToString(string format);

Summary

Returns a String representation of the value of the current instance.

Parameters

format
A String that specifies the format of the returned string. [Note: For a list of valid values, see System.Decimal.ToString (String, IFormatProvider ).]

Return Value

A String representation of the current instance formatted as specified by format. The string takes into account the current system culture.

Exceptions

Exception TypeCondition
FormatExceptionformat is invalid.

Description

This version of System.Decimal.ToString is equivalent to System.Decimal.ToString (format , null ).

If format is a null reference, the general format specifier "G" is used.

Example

The following example shows the effects of various formats on the string returned by System.Decimal.ToString.

using System;
class test {
 public static void Main() {
 decimal d = 1234.56789m;
 Console.WriteLine(d);
 string[] fmts = {"C","E","F","G","N","P"};
 for (int i=0;i<fmts.Length;i++)
 Console.WriteLine("{0}: {1}", 
 fmts[i],d.ToString(fmts[i]));
 }
}
   
The output is

1234.56789

C: $1,234.57

E: 1.234568E+003

F: 1234.57

G: 1234.56789

N: 1,234.57

P: 123,456.79 %

See Also

System.Decimal Structure, System Namespace

Decimal.ToString() Method

public override string ToString();

Summary

Returns a canonical String representation of the value of the current instance.

Return Value

A String representation of the current instance formatted using the general format specifier, ("G"). The string takes into account the current system culture and preserves the scale of the number.

Description

This version of System.Decimal.ToString is equivalent to System.Decimal.ToString (null , null ).

[Note: The general format specifier formats the number in either fixed-point or exponential notation form, preserving the scale of the number. For a detailed description of the general format, see the IFormattable interface.

This method overrides System.Object.ToString .

]

See Also

System.Decimal Structure, System Namespace

Decimal.ToString(System.String, System.IFormatProvider) Method

public string ToString(string format, IFormatProvider provider);

Summary

Returns a String representation of the value of the current instance.

Parameters

format
A String containing a character that specifies the format of the returned string, optionally followed by a non-negative integer that specifies the precision of the number in the returned String .
provider
A IFormatProvider that supplies a NumberFormatInfo instance containing culture-specific formatting information.

Return Value

A String representation of the current instance formatted as specified by format. The string takes into account the information in the NumberFormatInfo instance supplied by provider.

Exceptions

Exception TypeCondition
FormatExceptionformat is invalid.

Description

If provider is null or if a NumberFormatInfo cannot be obtained from provider , the formatting information for the current system culture is used.

The following table lists the characters that are valid for the format parameter.

Format CharactersDescription
"C", "c"Currency format.
"E", "e"Exponential notation format.
"F", "f"Fixed-point format.
"G", "g"General format.
"N", "n"Number format.
"P", "p"Percent format.
If format is a null reference, the general format specifier "G" is used.

[Note: For a detailed description of formatting, see the IFormattable interface.

This method is implemented to support the IFormattable interface.

]

See Also

System.Decimal Structure, System Namespace

Decimal.ToString(System.IFormatProvider) Method

public string ToString(IFormatProvider provider);

Summary

Returns a String representation of the value of the current instance.

Parameters

provider
A IFormatProvider that supplies a NumberFormatInfo containing culture-specific formatting information.

Return Value

A String representation of the current instance formatted using the general format specifier, ("G"). The string takes into account the formatting information in the NumberFormatInfo instance supplied by provider.

Description

This version of System.Decimal.ToString is equivalent to System.Decimal.ToString (null , provider ).

If provider is null or if a NumberFormatInfo cannot be obtained from provider, the formatting information for the current system culture is used.

[Note: The general format specifier formats the number in either fixed-point or exponential notation form. For a detailed description of the general format, see the IFormattable interface.]

See Also

System.Decimal Structure, System Namespace

Decimal.Truncate Method

public static decimal Truncate(decimal d);

Summary

Rounds a Decimal value towards zero, to the closest integer value.

Parameters

d
The Decimal to truncate.

Return Value

The Decimal result of truncating d . the scale of the result is 0.

Example

The following example demonstrates using the System.Decimal.Truncate(System.Decimal) method.

using System;
class MyClass {
public static void Main() {
 decimal d1 = 1234.56789m;
 decimal d2 = -1234.56789m;
 Console.WriteLine("{0} truncated is {1}", d1, Decimal.Truncate(d1));
 Console.WriteLine("{0} truncated is {1}", d2, Decimal.Truncate(d2));
}
}
The output is

1234.56789 truncated is 1234

-1234.56789 truncated is -1234

See Also

System.Decimal Structure, System Namespace

Decimal.op_Addition Method

public static Decimal operator +(Decimal d1, Decimal d2);

Summary

Adds two Decimal values together.

Parameters

d1
The first addend.
d2
The second addend.

Return Value

The value returned by System.Decimal.Add(System.Decimal,System.Decimal) (d1,d2).

Exceptions

Exception TypeCondition
OverflowExceptionThe sum of d1 and d2 is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.

See Also

System.Decimal Structure, System Namespace

Decimal.op_Decrement Method

public static Decimal operator --(Decimal d);

Summary

Returns the specified value decremented by one.

Parameters

d
A Decimal value.

Return Value

The value returned by System.Decimal.Subtract(System.Decimal,System.Decimal) (d , System.Decimal.One ).

Exceptions

Exception TypeCondition
OverflowExceptionThe result is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue .

See Also

System.Decimal Structure, System Namespace

Decimal.op_Division Method

public static Decimal operator /(Decimal d1, Decimal d2);

Summary

Divides one Decimal value by another Decimal .

Parameters

d1
The dividend.
d2
The divisor.

Return Value

The value returned by System.Decimal.Divide(System.Decimal,System.Decimal) (d1, d2).

Exceptions

Exception TypeCondition
DivideByZeroExceptionThe divisor is zero.
OverflowExceptionThe result is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.

See Also

System.Decimal Structure, System Namespace

Decimal.op_Equality Method

public static bool operator ==(Decimal d1, Decimal d2);

Summary

Determines whether two decimals have the same value.

Parameters

d1
The first Decimal to compare.
d2
The second Decimal to compare.

Return Value

true if System.Decimal.Compare(System.Decimal,System.Decimal) (d1, d2 ) returns zero; otherwise false .

See Also

System.Decimal Structure, System Namespace

double Decimal.op_Explicit(System.Decimal) Method

public static explicit operator double(Decimal value);

Summary

Perform an explicit conversion of a Decimal value to Double .

Parameters

value
The Decimal value to convert to Double .

Return Value

A Double with the specified value.

Description

[Note: This operation can produce round-off errors due to the fact that Double has fewer significant digits than, and has a different radix than, Decimal.]

See Also

System.Decimal Structure, System Namespace

float Decimal.op_Explicit(System.Decimal) Method

public static explicit operator float(Decimal value);

Summary

Perform an explicit conversion of a Decimal value to Single .

Parameters

value
The Decimal value to convert to Single .

Return Value

A Single with the specified value.

[Note: This operation can produce round-off errors due to the fact that Single has fewer significant digits than, and has a different radix than, Decimal.]

See Also

System.Decimal Structure, System Namespace

ulong Decimal.op_Explicit(System.Decimal) Method

public static explicit operator ulong(Decimal value);

Summary

Perform an explicit conversion of a Decimal value to UInt64 .

Parameters

value
The Decimal value to convert to UInt64 .

Return Value

A UInt64 containing value rounded towards zero to the nearest integer.

Exceptions

Exception TypeCondition
OverflowExceptionThe resulting integer value is greater than System.UInt64.MaxValue or less than System.UInt64.MinValue.

Description

This member is not CLS-compliant. For a CLS-compliant alternative to UInt64, use Int64 .

Attributes

CLSCompliantAttribute(false)

See Also

System.Decimal Structure, System Namespace

long Decimal.op_Explicit(System.Decimal) Method

public static explicit operator long(Decimal value);

Summary

Perform an explicit conversion of a Decimal value to Int64 .

Parameters

value
The Decimal value to convert to Int64 .

Return Value

A Int64 containing value rounded towards zero to the nearest integer.

Exceptions

Exception TypeCondition
OverflowExceptionThe resulting integer value is greater than System.Int64.MaxValue or less than System.Int64.MinValue.

See Also

System.Decimal Structure, System Namespace

uint Decimal.op_Explicit(System.Decimal) Method

public static explicit operator uint(Decimal value);

Summary

Perform an explicit conversion of a Decimal value to UInt32 .

Parameters

value
The Decimal value to convert to UInt32 .

Return Value

A UInt32 containing value rounded towards zero to the nearest integer.

Exceptions

Exception TypeCondition
OverflowExceptionThe resulting integer value is greater than System.UInt32.MaxValue or less than System.UInt32.MinValue.

Description

This member is not CLS-compliant. For a CLS-compliant alternative to UInt32, use Int64 ).

Attributes

CLSCompliantAttribute(false)

See Also

System.Decimal Structure, System Namespace

int Decimal.op_Explicit(System.Decimal) Method

public static explicit operator int(Decimal value);

Summary

Perform an explicit conversion of a Decimal value to Int32 .

Parameters

value
The Decimal value to convert to Int32 .

Return Value

A Int32 containing value rounded towards zero to the nearest integer.

Exceptions

Exception TypeCondition
OverflowExceptionThe resulting integer value is greater than System.Int32.MaxValue or less than System.Int32.MinValue.

See Also

System.Decimal Structure, System Namespace

sbyte Decimal.op_Explicit(System.Decimal) Method

public static explicit operator sbyte(Decimal value);

Summary

Perform an explicit conversion of a Decimal value to SByte .

Parameters

value
The Decimal value to convert to SByte.

Return Value

A SByte containing value rounded towards zero to the nearest integer.

Exceptions

Exception TypeCondition
OverflowExceptionThe resulting integer value is greater than System.SByte.MaxValue or less than System.SByte.MinValue.

Description

This member is not CLS-compliant. For a CLS-compliant alternative to SByte, use Int16 .

Attributes

CLSCompliantAttribute(false)

See Also

System.Decimal Structure, System Namespace

byte Decimal.op_Explicit(System.Decimal) Method

public static explicit operator byte(Decimal value);

Summary

Perform an explicit conversion of a Decimal value to Byte .

Parameters

value
The Decimal value to convert to Byte .

Return Value

A Byte containing value rounded towards zero to the nearest integer.

Exceptions

Exception TypeCondition
OverflowExceptionThe resulting integer value is greater than System.Byte.MaxValue or less than System.Byte.MinValue.

See Also

System.Decimal Structure, System Namespace

System.Decimal Decimal.op_Explicit(double) Method

public static explicit operator Decimal(double value);

Summary

Perform an explicit conversion of a Double value to Decimal.

Parameters

value
The Double value to convert to Decimal .

Return Value

A Decimal with the specified value.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is one of the following:

greater than System.Decimal.MaxValue

less than System.Decimal.MinValue

equal to System.Double.NaN, but the Decimal representation does not support NaNs.

equal to System.Double.PositiveInfinity, but the Decimal representation does not support infinities.

equal to System.Double.NegativeInfinity, but the Decimal representation does not support infinities.

See Also

System.Decimal Structure, System Namespace

System.Decimal Decimal.op_Explicit(float) Method

public static explicit operator Decimal(float value);

Summary

Perform an explicit conversion of a Single value to Decimal.

Parameters

value
The Single value to convert to Decimal .

Return Value

A Decimal with the specified value.

Exceptions

Exception TypeCondition
OverflowExceptionvalue is one of the following:

greater than System.Decimal.MaxValue

less than System.Decimal.MinValue

equal to System.Single.NaN, but the Decimal representation does not support NaNs.

equal to System.Single.PositiveInfinity, but the Decimal representation does not support infinities.

equal to System.Single.NegativeInfinity, but the Decimal representation does not support infinities.

See Also

System.Decimal Structure, System Namespace

char Decimal.op_Explicit(System.Decimal) Method

public static explicit operator char(Decimal value);

Summary

Perform an explicit conversion of a Decimal value to Char .

Parameters

value
The Decimal value to convert to Char .

Return Value

A Char containing value rounded towards zero to the nearest integer.

Exceptions

Exception TypeCondition
OverflowExceptionThe resulting integer value is greater than System.Char.MaxValue or less than System.Char.MinValue.

See Also

System.Decimal Structure, System Namespace

ushort Decimal.op_Explicit(System.Decimal) Method

public static explicit operator ushort(Decimal value);

Summary

Perform an explicit conversion of a Decimal value to UInt16 .

Parameters

value
The Decimal value to convert to UInt16 .

Return Value

A UInt16 containing value rounded towards zero to the nearest integer.

Exceptions

Exception TypeCondition
OverflowExceptionThe resulting integer value is greater than System.UInt16.MaxValue or less than System.UInt16.MinValue.

Description

This member is not CLS-compliant. For a CLS-compliant alternative to UInt16, use Int32 .

Attributes

CLSCompliantAttribute(false)

See Also

System.Decimal Structure, System Namespace

short Decimal.op_Explicit(System.Decimal) Method

public static explicit operator short(Decimal value);

Summary

Perform an explicit conversion of a Decimal value to Int16 .

Parameters

value
The Decimal value to convert to Int16 .

Return Value

A Int16 containing value rounded towards zero to the nearest integer.

Exceptions

Exception TypeCondition
OverflowExceptionThe resulting integer value is greater than System.Int16.MaxValue or less than System.Int16.MinValue.

See Also

System.Decimal Structure, System Namespace

Decimal.op_GreaterThan Method

public static bool operator >(Decimal d1, Decimal d2);

Summary

Determines whether one Decimal value is greater than another Decimal value.

Parameters

d1
The first Decimal to compare.
d2
The second Decimal to compare.

Return Value

true if System.Decimal.Compare(System.Decimal,System.Decimal) (d1, d2) returns a value that is greater than zero; otherwise false .

See Also

System.Decimal Structure, System Namespace

Decimal.op_GreaterThanOrEqual Method

public static bool operator >=(Decimal d1, Decimal d2);

Summary

Determines whether one Decimal value is greater than or equal to another Decimal value.

Parameters

d1
The first Decimal to compare.
d2
The second Decimal to compare.

Return Value

true if System.Decimal.Compare(System.Decimal,System.Decimal) (d1, d2) returns a value that is greater than or equal to zero; otherwise false .

See Also

System.Decimal Structure, System Namespace

System.Decimal Decimal.op_Implicit(byte) Method

public static implicit operator Decimal(byte value);

Summary

Perform an implicit conversion of a Byte value to Decimal.

Parameters

value
The Byte value to convert to Decimal .

Return Value

A Decimal with the specified value.

See Also

System.Decimal Structure, System Namespace

System.Decimal Decimal.op_Implicit(sbyte) Method

public static implicit operator Decimal(sbyte value);

Summary

Perform an implicit conversion of a SByte value to Decimal.

Parameters

value
The SByte value to convert to Decimal .

Return Value

A Decimal with the specified value.

Description

This member is not CLS-compliant.

Attributes

CLSCompliantAttribute(false)

See Also

System.Decimal Structure, System Namespace

System.Decimal Decimal.op_Implicit(short) Method

public static implicit operator Decimal(short value);

Summary

Perform an implicit conversion of a Int16 value to Decimal.

Parameters

value
The Int16 value to convert to Decimal.

Return Value

A Decimal with the specified value.

See Also

System.Decimal Structure, System Namespace

System.Decimal Decimal.op_Implicit(ushort) Method

public static implicit operator Decimal(ushort value);

Summary

Perform an implicit conversion of a UInt16 value to Decimal.

Parameters

value
The UInt16 value to convert to Decimal .

Return Value

A Decimal with the specified value.

Description

This member is not CLS-compliant.

Attributes

CLSCompliantAttribute(false)

See Also

System.Decimal Structure, System Namespace

System.Decimal Decimal.op_Implicit(char) Method

public static implicit operator Decimal(char value);

Summary

Perform an implicit conversion of a Char value to Decimal.

Parameters

value
The Char value to convert to Decimal .

Return Value

A Decimal with the specified value.

See Also

System.Decimal Structure, System Namespace

System.Decimal Decimal.op_Implicit(int) Method

public static implicit operator Decimal(int value);

Summary

Perform an implicit conversion of a Int32 value to Decimal.

Parameters

value
The Int32 value to convert to Decimal .

Return Value

A Decimal with the specified value.

See Also

System.Decimal Structure, System Namespace

System.Decimal Decimal.op_Implicit(uint) Method

public static implicit operator Decimal(uint value);

Summary

Perform an implicit conversion of a UInt32 value to Decimal.

Parameters

value
The UInt32 value to convert to Decimal .

Return Value

A Decimal with the specified value.

Description

This member is not CLS-compliant.

Attributes

CLSCompliantAttribute(false)

See Also

System.Decimal Structure, System Namespace

System.Decimal Decimal.op_Implicit(long) Method

public static implicit operator Decimal(long value);

Summary

Perform an implicit conversion of a Int64 value to Decimal.

Parameters

value
The Int64 value to convert to Decimal .

Return Value

A Decimal with the specified value.

See Also

System.Decimal Structure, System Namespace

System.Decimal Decimal.op_Implicit(ulong) Method

public static implicit operator Decimal(ulong value);

Summary

Perform an implicit conversion of a UInt64 value to Decimal.

Parameters

value
The UInt64 value to convert to Decimal .

Return Value

A Decimal with the specified value.

Description

This member is not CLS-compliant.

Attributes

CLSCompliantAttribute(false)

See Also

System.Decimal Structure, System Namespace

Decimal.op_Increment Method

public static Decimal operator ++(Decimal d);

Summary

Returns the specified value incremented by one.

Parameters

d
A Decimal value.

Return Value

The value returned by System.Decimal.Add(System.Decimal,System.Decimal) (d , System.Decimal.One ).

Exceptions

Exception TypeCondition
OverflowExceptionThe result is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue .

See Also

System.Decimal Structure, System Namespace

Decimal.op_Inequality Method

public static bool operator !=(Decimal d1, Decimal d2);

Summary

Determines whether two decimals do not have the same value.

Parameters

d1
The first Decimal to compare.
d2
The second Decimal to compare.

Return Value

true if System.Decimal.Compare(System.Decimal,System.Decimal) (d1, d2) does not return zero; otherwise false .

See Also

System.Decimal Structure, System Namespace

Decimal.op_LessThan Method

public static bool operator  <(Decimal d1, Decimal d2);

Summary

Determines whether one Decimal value is less than another Decimal value.

Parameters

d1
The first Decimal to compare.
d2
The first Decimal to compare.

Return Value

true if System.Decimal.Compare(System.Decimal,System.Decimal) (d1, d2) returns a value that is less than zero; otherwise false .

See Also

System.Decimal Structure, System Namespace

Decimal.op_LessThanOrEqual Method

public static bool operator <=(Decimal d1, Decimal d2);

Summary

Determines whether one Decimal value is less than or equal to another Decimal value.

Parameters

d1
The first Decimal to compare.
d2
The second Decimal to compare.

Return Value

true if System.Decimal.Compare(System.Decimal,System.Decimal) (d1, d2) returns a value that is less than or equal to zero; otherwise false .

See Also

System.Decimal Structure, System Namespace

Decimal.op_Modulus Method

public static Decimal operator %(Decimal d1, Decimal d2);

Summary

Divides one Decimal value by another Decimal and returns the remainder.

Parameters

d1
The dividend.
d2
The divisor.

Return Value

The value returned by System.Decimal.Remainder(System.Decimal,System.Decimal) (d1, d2).

Exceptions

Exception TypeCondition
DivideByZeroExceptiond2 is zero.
OverflowExceptiond1 divided by d2 is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.

See Also

System.Decimal Structure, System Namespace

Decimal.op_Multiply Method

public static Decimal operator *(Decimal d1, Decimal d2);

Summary

Returns the result of multiplying two Decimal values.

Parameters

d1
The multiplier.
d2
The multiplicand.

Return Value

The value returned by System.Decimal.Multiply(System.Decimal,System.Decimal) (d1, d2).

Exceptions

Exception TypeCondition
OverflowExceptionThe result is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.

See Also

System.Decimal Structure, System Namespace

Decimal.op_Subtraction Method

public static Decimal operator -(Decimal d1, Decimal d2);

Summary

Subtracts one Decimal value from another.

Parameters

d1
The minuend.
d2
The subtrahend.

Return Value

The value returned by System.Decimal.Subtract(System.Decimal,System.Decimal) (d1, d2 ).

Exceptions

Exception TypeCondition
OverflowExceptionThe result is greater than System.Decimal.MaxValue or less than System.Decimal.MinValue.

See Also

System.Decimal Structure, System Namespace

Decimal.op_UnaryNegation Method

public static Decimal operator -(Decimal d);

Summary

Returns the specified value multiplied by negative one (-1).

Parameters

d
A Decimal value.

Return Value

The value returned by System.Decimal.Negate(System.Decimal) (d).

See Also

System.Decimal Structure, System Namespace

Decimal.op_UnaryPlus Method

public static Decimal operator +(Decimal d);

Summary

Returns the specified value.

Parameters

d
A Decimal value.

Return Value

Returns d.

See Also

System.Decimal Structure, System Namespace

Decimal.MaxValue Field

public static readonly decimal MaxValue;

Summary

Contains the maximum positive value for the Decimal type.

Description

The value of this constant is implementation-specific, but shall be greater than or equal to 79228162514264337593543950335. The scale shall be 0.

This field is read-only.

Attributes

DecimalConstantAttribute

See Also

System.Decimal Structure, System Namespace

Decimal.MinValue Field

public static readonly decimal MinValue;

Summary

Contains the minimum (most negative) value for the Decimal type.

Description

The value of this constant is implementation-specific, but shall be less than or equal to -79228162514264337593543950335. The scale shall be 0.

This field is read-only.

Attributes

DecimalConstantAttribute

See Also

System.Decimal Structure, System Namespace

Decimal.MinusOne Field

public static readonly decimal MinusOne;

Summary

Contains negative one (-1).

Description

The value of this constant is -1. The scale shall be 0.

This field is read-only.

Attributes

DecimalConstantAttribute

See Also

System.Decimal Structure, System Namespace

Decimal.One Field

public static readonly decimal One;

Summary

Contains one (1).

Description

The value of this constant is 1. The scale shall be 0.

This field is read-only.

Attributes

DecimalConstantAttribute

See Also

System.Decimal Structure, System Namespace

Decimal.Zero Field

public static readonly decimal Zero;

Summary

Contains zero (0).

Description

The value of this constant is 0. The scale shall be 0.

This field is read-only.

Attributes

DecimalConstantAttribute

See Also

System.Decimal Structure, System Namespace