System.Decimal Structure

public struct Decimal : IComparable, IFormattable

Base Types

Object
  ValueType
    Decimal

This type implements IFormattable and IComparable.

Assembly

mscorlib

Library

ExtendedNumerics

Summary

Represents a floating-point decimal data type with up to 29 significant digits, suitable for financial and commercial calculations.

Description

The Decimal type can represent values from approximately -7.9 x 1028 to 7.9 x 1028, with 28 or 29 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 finite set of values of type decimal are of the form -1s x c x 10-f, where the sign s is 0 or 1, the coefficient c is given by 0 <= c < 296 , and the scale f is such that 0 <= f <= 28.

A Decimal is represented as a 96-bit integer scaled by a power of ten. For a Decimal with an absolute value less than 1.0, the value is exact to the 28th decimal place, but no further. For a Decimal with an absolute value greater than or equal to 1.0, the value is exact to 28 or 29 digits.

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 28 or 29 digits, but to no more than 28 decimal places. A zero result has a sign of 0 and a scale 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).

[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 may lose precision, but will not lose information about the overall magnitude of the numeric value, and will never throw an exception. A conversion from Single or Double to Decimal throws a OverflowException if the value is not within the range of the Decimal type.

]

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 Method
Decimal.Divide 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.IFormatProvider) Method
Decimal.ToString(System.String, System.IFormatProvider) Method
Decimal.ToString() Method
Decimal.ToString(System.String) Method
Decimal.Truncate Method
Decimal.op_Addition Method
Decimal.op_Decrement Method
Decimal.op_Division Method
Decimal.op_Equality Method
System.Decimal Decimal.op_Explicit(float) Method
System.Decimal Decimal.op_Explicit(double) Method
byte Decimal.op_Explicit(System.Decimal) Method
sbyte Decimal.op_Explicit(System.Decimal) Method
char Decimal.op_Explicit(System.Decimal) Method
short Decimal.op_Explicit(System.Decimal) Method
ushort Decimal.op_Explicit(System.Decimal) Method
int Decimal.op_Explicit(System.Decimal) Method
uint Decimal.op_Explicit(System.Decimal) Method
long Decimal.op_Explicit(System.Decimal) Method
ulong Decimal.op_Explicit(System.Decimal) Method
float Decimal.op_Explicit(System.Decimal) Method
double 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.

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.

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.

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.

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

equal to System.Single.PositiveInfinity

equal to System.Single.NegativeInfinity

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.

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

equal to System.Double.PositiveInfinity

equal to System.Double.NegativeInfinity

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.

See Also

System.Decimal Structure, System Namespace

Decimal(int[]) Constructor

public Decimal(int[] bits);

Summary

Constructs and initializes a new Decimal value.

Parameters

bits
A Int32 array containing a bit representation of a Decimal. bits 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. See below.

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: The elements of bits represent a Decimal as a coefficient c , a scale f, and sign bit s. The decimal value is computed as -1s x c x 10-f. The coefficient c is divided into three 32-bit integer values.]

The sign and scale occupy a total of 32 bits as follows:

Bit PositionsName
0-15(None.)
16-23 Scale
24-30 (None.)
31 Sign
[Note: A numeric value may 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 and a scale of 0.]

Example

The following example demonstrates using the Decimal (Int32 []) constructor.

using System;
class ConstructDecimal {
 public static void Main() {
 int negativeBitValue = unchecked ((int)0x80000000);
 int [] parts0 = {0,0,0,0}; //Positive Zero.
 int [] parts1 = {1,0,0,0};
 int [] parts2 = {0,1,0,0};
 int [] parts3 = {0,0,1,0};
 int [] parts4 = {0,0,0,negativeBitValue}; // Negative zero.
 int [] parts5 = {1,1,1,0};
 int [] partsMaxValue = {-1,-1,-1,0};
 int [] partsMinValue = {-1,-1,-1,negativeBitValue};

 decimal d = new Decimal(parts0);
 Console.WriteLine("{{0,0,0,0}} = {0}",d);
 d = new Decimal(parts1);
 Console.WriteLine("{{1,0,0,0}} = {0}",d);
 d = new Decimal(parts2);
 Console.WriteLine("{{0,1,0,0}} = {0}",d);
 d = new Decimal(parts3);
 Console.WriteLine("{{0,0,1,0}} = {0}",d);
 d = new Decimal(parts4);
 Console.WriteLine("{{0,0,0,{0}}} = {1}",parts4[3],d);
 d = new Decimal(parts5);
 Console.WriteLine("{{1,1,1,0}} = {0}",d);
 d = new Decimal(partsMaxValue );
 Console.WriteLine("{{-1,-1,-1,0}} = {0}",d);
 d = new Decimal(partsMinValue);
 Console.WriteLine("{{-1,-1,-1,{0}}} = {1}",partsMinValue [3],d);
 }
}
The output is

{0,0,0,0} = 0

{1,0,0,0} = 1

{0,1,0,0} = 4294967296

{0,0,1,0} = 18446744073709551616

{0,0,0,-2147483648} = 0

{1,1,1,0} = 18446744078004518913

{-1,-1,-1,0} = 79228162514264337593543950335

{-1,-1,-1,-2147483648} = -79228162514264337593543950335

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 value to add..
d2
The second value to add.

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

A Int32 containing a value that reflects the sort order of d1 and d2. The exact value returned by this method is implementation defined. The following table defines the conditions under which the returned value is a negative number, zero, or a positive number. Each comparison compares the numerical values of d1 and d2.

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

See Also

System.Decimal Structure, System Namespace

Decimal.CompareTo 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

A Int32 containing a value that reflects the sort order of the current instance as compared to value. The following table defines the conditions under which the returned value is a negative number, zero, or a positive number. Each comparison compares the numerical values of d1 and d2.

Return ValueDescription
Any negative numberCurrent instance < value.
ZeroCurrent instance == value.
Any 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 decimal Divide(decimal d1, 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 smallest scale that will preserve a result equal to the exact result. For example, 2.22 / 2 gives 1.11.

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.Object) Method

public override bool Equals(object value);

Summary

Determines whether the current instance and the specified Object have the same type and value.

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.

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 a whole number 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 type Int32 containing the following four elements:

IndexDescription
0 Low-order 32 bits of the decimal's coefficient, c.
1 Middle 32 bits of c.
2 High-order 32 bits of c.
3 Sign bit and scale. See below.
The sign bit and scale occupy 32 bits as follows:

Bit PositionsDescription
0-15Unused.
16-23 Contains the scale f, a value between 0 and 28 which indicates the power of 10 to divide c by, to produce the Decimal value.
24-30 Unused.
31 The sign, s , of the Decimal value. 0 (zero or positive) or 1 (negative).

Description

[Note: The elements of the returned array contain a binary representation of d as a coefficient c a scale f and sign bit s. The value of d is computed as -1s x c x 10-f .

c occupies the first three elements of the returned array. The fourth element contains f and s .

]

A numeric value may 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 and a scale 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);
}
}
   
The output is

1.00 - bits: 100 0 0 512

1 - bits: 1 0 0 0

d1.CompareTo(d) == 0

d1 == d True

See Also

System.Decimal Structure, System Namespace

Decimal.GetHashCode Method

public override int GetHashCode();

Summary

Generates a hash code for the current instance.

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 first value to multiply.
d2
The second value to multiply.

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 and scale); 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 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 or the value is zero (in which latter case the sign and 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 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 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 or the value is zero (in which latter case the sign and 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 same as the scale of 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.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.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.
"Z", "z"Normalize format (trims trailing zeros).
"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() 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) 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.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 value to add.
d2
The second value to add.

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

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

equal to System.Single.PositiveInfinity

equal to System.Single.NegativeInfinity

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

equal to System.Double.PositiveInfinity

equal to System.Double.NegativeInfinity

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

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

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

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

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

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

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

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

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

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 Decimal.]

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 Decimal.]

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 first operand.
d2
The second operand.

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 left-side operand.
d2
The right-side operand.

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 79228162514264337593543950335.

This field is read-only.

Attributes

DecimalConstantAttribute(79228162514264337593543950335, 79228162514264337593543950335, 79228162514264337593543950335, 79228162514264337593543950335, 79228162514264337593543950335)

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 -79228162514264337593543950335.

This field is read-only.

Attributes

DecimalConstantAttribute(-79228162514264337593543950335, -79228162514264337593543950335, -79228162514264337593543950335, -79228162514264337593543950335, -79228162514264337593543950335)

See Also

System.Decimal Structure, System Namespace

Decimal.MinusOne Field

public static readonly decimal MinusOne;

Summary

Contains negative one (-1).

Description

This field is read-only.

Attributes

DecimalConstantAttribute(-1, -1, -1, -1, -1)

See Also

System.Decimal Structure, System Namespace

Decimal.One Field

public static readonly decimal One;

Summary

Contains one (1).

Description

This field is read-only.

Attributes

DecimalConstantAttribute(1, 1, 1, 1, 1)

See Also

System.Decimal Structure, System Namespace

Decimal.Zero Field

public static readonly decimal Zero;

Summary

Contains zero (0).

Description

This field is read-only.

Attributes

DecimalConstantAttribute(0, 0, 0, 0, 0)

See Also

System.Decimal Structure, System Namespace