BigDecimal Struct
Definition
Represents an immutable, arbitrary-precision decimal number - a BigInteger unscaled value together with a base-ten scale.
public readonly struct BigDecimal : INumber<BigDecimal>, IComparable, IComparable<BigDecimal>, IComparisonOperators<BigDecimal, BigDecimal, bool>, IModulusOperators<BigDecimal, BigDecimal, BigDecimal>, ISignedNumber<BigDecimal>, INumberBase<BigDecimal>, IEquatable<BigDecimal>, ISpanFormattable, IFormattable, ISpanParsable<BigDecimal>, IParsable<BigDecimal>, IUtf8SpanFormattable, IUtf8SpanParsable<BigDecimal>, IAdditionOperators<BigDecimal, BigDecimal, BigDecimal>, IAdditiveIdentity<BigDecimal, BigDecimal>, IDecrementOperators<BigDecimal>, IDivisionOperators<BigDecimal, BigDecimal, BigDecimal>, IEqualityOperators<BigDecimal, BigDecimal, bool>, IIncrementOperators<BigDecimal>, IMultiplicativeIdentity<BigDecimal, BigDecimal>, IMultiplyOperators<BigDecimal, BigDecimal, BigDecimal>, ISubtractionOperators<BigDecimal, BigDecimal, BigDecimal>, IUnaryNegationOperators<BigDecimal, BigDecimal>, IUnaryPlusOperators<BigDecimal, BigDecimal>
- Implements
- Inherited Members
- Extension Methods
Examples
BigDecimal price = BigDecimal.Parse("19.99");
BigDecimal tax = price * BigDecimal.Parse("0.10"); // 1.999
BigDecimal total = price + tax; // 21.989
BigDecimal third = BigDecimal.One / 3; // 0.3333… (50 places, half-even)
BigDecimal half = BigDecimal.One / 2; // 0.5 (exact)
Remarks
A BigDecimal is the value UnscaledValue × 10-Scale. Unlike
decimal it has no fixed precision or range limit: both the number of significant digits and the
exponent grow as needed.
Every value is held in a single canonical form so equal values share one representation and compare and hash
equally: trailing zeros are removed from the unscaled value down to - but never past - a scale of zero, so
1.0 and 1.00 are the same value, and an integer such as 100 keeps a scale of zero.
Addition, subtraction, multiplication, and remainder are exact. Division is generally not exact (for example
1 / 3), so the / operator and Divide(BigDecimal, BigDecimal) round to a default working
scale of DefaultDivisionScale decimal places using ToEven; use
Divide(BigDecimal, BigDecimal, int, MidpointRounding) to choose the scale and rounding explicitly.
Exact quotients self-trim through canonicalization, so 1 / 2 is 0.5.
Constructors
BigDecimal(BigInteger)
Initializes a new instance of the BigDecimal struct representing the integer
value.
public BigDecimal(BigInteger value)
Parameters
valueBigIntegerThe integer value the decimal represents.
BigDecimal(BigInteger, int)
Initializes a new instance of the BigDecimal struct from an unscaled value and scale, reducing the result to canonical form.
public BigDecimal(BigInteger unscaledValue, int scale)
Parameters
unscaledValueBigIntegerThe unscaled integer significand.
scaleintThe base-ten scale; a negative scale multiplies the unscaled value by
10-scale.
Fields
DefaultDivisionScale
The default number of fractional decimal places produced by the / operator and Divide(BigDecimal, BigDecimal).
public const int DefaultDivisionScale = 50
Field Value
Properties
IsInteger
Gets a value indicating whether the value is an integer - has no fractional part.
public bool IsInteger { get; }
Property Value
IsNegative
Gets a value indicating whether the value is negative.
public bool IsNegative { get; }
Property Value
IsPositive
Gets a value indicating whether the value is positive - strictly greater than zero.
public bool IsPositive { get; }
Property Value
IsZero
Gets a value indicating whether the value is zero.
public bool IsZero { get; }
Property Value
MinusOne
Gets a BigDecimal representing the value negative one.
public static BigDecimal MinusOne { get; }
Property Value
- BigDecimal
The value
-1.
Precision
Gets the precision - the number of significant decimal digits in the unscaled value.
public int Precision { get; }
Property Value
- int
The digit count of the unscaled value;
1for zero.
Scale
Gets the base-ten scale of the canonical form - the number of fractional decimal places.
public int Scale { get; }
Property Value
- int
A non-negative scale; zero for an integer value.
Sign
Gets the sign of the value.
public int Sign { get; }
Property Value
- int
-1when negative,0when zero, and1when positive.
Ten
Gets a BigDecimal representing the value ten.
public static BigDecimal Ten { get; }
Property Value
- BigDecimal
The value
10.
UnscaledValue
Gets the unscaled integer significand of the canonical form.
public BigInteger UnscaledValue { get; }
Property Value
- BigInteger
The value
Vsuch that this decimal equalsV × 10-Scale.
Methods
Abs(BigDecimal)
Returns the absolute value.
public static BigDecimal Abs(BigDecimal value)
Parameters
valueBigDecimalThe value.
Returns
- BigDecimal
The magnitude of
value.
Add(BigDecimal, BigDecimal)
Adds two values exactly.
public static BigDecimal Add(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe first value.
rightBigDecimalThe second value.
Returns
- BigDecimal
The exact sum.
Ceiling(BigDecimal)
Returns the smallest integer value greater than or equal to value.
public static BigDecimal Ceiling(BigDecimal value)
Parameters
valueBigDecimalThe value to ceiling.
Returns
- BigDecimal
The ceiling of
value.
CompareTo(BigDecimal)
Compares this value with another BigDecimal.
public int CompareTo(BigDecimal other)
Parameters
otherBigDecimalThe value to compare with.
Returns
- int
A negative number when this value is less than
other, zero when they are equal, and a positive number when this value is greater.
Remarks
The comparison decides on sign, then on equal scales, then on the operands' integer-magnitude bounds, and only
rescales to a common scale when the magnitudes genuinely overlap. Rescaling multiplies an unscaled value by
10 raised to the scale gap, so short-circuiting first bounds the transient allocation that a pathological
scale difference would otherwise force on every comparison.
CompareTo(object?)
Compares this value with another object.
public int CompareTo(object? obj)
Parameters
objobjectThe object to compare with, which must be a BigDecimal or null.
Returns
- int
A negative number when this value is less than
obj, zero when they are equal, and a positive number when this value is greater. A null object sorts before every value.
Exceptions
- ArgumentException
objis not a BigDecimal.
Deconstruct(out BigInteger, out int)
Deconstructs the value into its canonical unscaled value and scale.
public void Deconstruct(out BigInteger unscaledValue, out int scale)
Parameters
unscaledValueBigIntegerWhen this method returns, contains the canonical unscaled value.
scaleintWhen this method returns, contains the canonical scale.
Divide(BigDecimal, BigDecimal)
Divides one value by another, rounding to DefaultDivisionScale decimal places using ToEven.
public static BigDecimal Divide(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe dividend.
rightBigDecimalThe divisor.
Returns
- BigDecimal
The quotient; an exact quotient is trimmed to its shortest canonical form.
Exceptions
- DivideByZeroException
rightis zero.
Divide(BigDecimal, BigDecimal, int, MidpointRounding)
Divides one value by another, rounding the result to the specified number of decimal places.
public static BigDecimal Divide(BigDecimal left, BigDecimal right, int scale, MidpointRounding mode)
Parameters
leftBigDecimalThe dividend.
rightBigDecimalThe divisor.
scaleintThe number of fractional decimal places to round the quotient to.
modeMidpointRoundingThe rounding mode applied at the requested scale.
Returns
- BigDecimal
The quotient rounded to
scaledecimal places, in canonical form.
Exceptions
- DivideByZeroException
rightis zero.- ArgumentOutOfRangeException
scaleis negative.
Equals(BigDecimal)
Determines whether this value equals another BigDecimal.
public bool Equals(BigDecimal other)
Parameters
otherBigDecimalThe value to compare with.
Returns
Remarks
Because every value is held in canonical form, numerically equal values (for example 1.0 and 1.00)
share the same unscaled value and scale and therefore compare equal.
Equals(object?)
Determines whether this value equals another object.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with.
Returns
- bool
true when
objis a BigDecimal equal to this value; otherwise false.
Floor(BigDecimal)
Returns the largest integer value less than or equal to value.
public static BigDecimal Floor(BigDecimal value)
Parameters
valueBigDecimalThe value to floor.
Returns
- BigDecimal
The floor of
value.
FromDecimal(decimal)
Converts a decimal to a BigDecimal exactly.
public static BigDecimal FromDecimal(decimal value)
Parameters
valuedecimalThe decimal value.
Returns
- BigDecimal
The exact decimal value.
FromDouble(double)
Converts a double to a BigDecimal via its shortest round-trip decimal text.
public static BigDecimal FromDouble(double value)
Parameters
valuedoubleThe value to convert.
Returns
- BigDecimal
The decimal value.
Exceptions
- ArgumentException
valueis not a finite number.
GetHashCode()
Returns a hash code consistent with Equals(BigDecimal).
public override int GetHashCode()
Returns
- int
A hash code for the value.
Max(BigDecimal, BigDecimal)
Returns the larger of two values.
public static BigDecimal Max(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe first value.
rightBigDecimalThe second value.
Returns
- BigDecimal
The greater of the two values.
Min(BigDecimal, BigDecimal)
Returns the smaller of two values.
public static BigDecimal Min(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe first value.
rightBigDecimalThe second value.
Returns
- BigDecimal
The lesser of the two values.
Multiply(BigDecimal, BigDecimal)
Multiplies two values exactly.
public static BigDecimal Multiply(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe first value.
rightBigDecimalThe second value.
Returns
- BigDecimal
The exact product.
Exceptions
- OverflowException
The resulting scale (
) does not fit in an int.left.Scale +right.Scale
Negate(BigDecimal)
Negates a value.
public static BigDecimal Negate(BigDecimal value)
Parameters
valueBigDecimalThe value to negate.
Returns
- BigDecimal
The additive inverse of
value.
Parse(string)
Parses the decimal text representation of a value.
public static BigDecimal Parse(string s)
Parameters
sstringThe text to parse.
Returns
- BigDecimal
The parsed value.
Exceptions
- ArgumentNullException
sis null.- FormatException
sis not a valid decimal representation.
Pow(BigDecimal, int)
Raises a value to an integer power.
public static BigDecimal Pow(BigDecimal value, int exponent)
Parameters
valueBigDecimalThe base value.
exponentintThe integer exponent.
Returns
- BigDecimal
valueraised toexponent. A non-negative exponent is exact; a negative exponent divides into one at DefaultDivisionScale decimal places.
Exceptions
- DivideByZeroException
valueis zero andexponentis negative.- OverflowException
The resulting scale (
) does not fit in an int.value.Scale ×exponent
Remainder(BigDecimal, BigDecimal)
Returns the remainder of dividing one value by another - the exact value of
left - Truncate(left / right) × right.
public static BigDecimal Remainder(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe dividend.
rightBigDecimalThe divisor.
Returns
- BigDecimal
The exact remainder, whose sign matches
left.
Exceptions
- DivideByZeroException
rightis zero.
Round(BigDecimal)
Rounds a value to the nearest integer using ToEven.
public static BigDecimal Round(BigDecimal value)
Parameters
valueBigDecimalThe value to round.
Returns
- BigDecimal
The nearest integer value.
Round(BigDecimal, int)
Rounds a value to the specified number of decimal places using ToEven.
public static BigDecimal Round(BigDecimal value, int scale)
Parameters
valueBigDecimalThe value to round.
scaleintThe number of fractional decimal places to round to.
Returns
- BigDecimal
The rounded value.
Exceptions
- ArgumentOutOfRangeException
scaleis negative.
Round(BigDecimal, int, MidpointRounding)
Rounds a value to the specified number of decimal places using the specified rounding mode.
public static BigDecimal Round(BigDecimal value, int scale, MidpointRounding mode)
Parameters
valueBigDecimalThe value to round.
scaleintThe number of fractional decimal places to round to.
modeMidpointRoundingThe rounding mode.
Returns
- BigDecimal
The rounded value; if
valuealready has fewer decimal places it is returned unchanged.
Exceptions
- ArgumentOutOfRangeException
scaleis negative, ormodeis not a defined MidpointRounding value.
Subtract(BigDecimal, BigDecimal)
Subtracts one value from another exactly.
public static BigDecimal Subtract(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe value to subtract from.
rightBigDecimalThe value to subtract.
Returns
- BigDecimal
The exact difference.
ToBigInteger()
Returns the integer part of the value, truncated toward zero.
public BigInteger ToBigInteger()
Returns
- BigInteger
The truncated integer value.
ToDecimal()
Converts the value to a decimal.
public decimal ToDecimal()
Returns
Exceptions
- OverflowException
The value is outside the range of decimal.
ToDouble()
Converts the value to the nearest double.
public double ToDouble()
Returns
- double
The nearest double, or PositiveInfinity / NegativeInfinity when the value lies outside the finite double range.
ToString()
Returns the plain (non-scientific) decimal string representation of the value using the invariant culture.
public override string ToString()
Returns
- string
The canonical decimal text, for example
"0.5","100", or"-3.14".
ToString(string?)
Formats the value using the specified format specifier and the invariant culture, consistent with the parameterless ToString().
public string ToString(string? format)
Parameters
formatstringThe format specifier:
"G"(or null) for the plain canonical form, or"F"optionally followed by a digit count for a fixed number of decimal places.
Returns
- string
The formatted text.
Exceptions
- FormatException
formatis not a supported specifier.
ToString(string?, IFormatProvider?)
Formats the value using the specified format specifier and format provider.
public string ToString(string? format, IFormatProvider? formatProvider)
Parameters
formatstringThe format specifier:
"G"(or null) for the plain canonical form, or"F"optionally followed by a digit count for a fixed number of decimal places.formatProviderIFormatProviderThe format provider supplying the decimal separator and sign symbols.
Returns
- string
The formatted text.
Exceptions
- FormatException
formatis not a supported specifier.
Truncate(BigDecimal)
Returns the integer part of value, discarding any fractional digits.
public static BigDecimal Truncate(BigDecimal value)
Parameters
valueBigDecimalThe value to truncate.
Returns
- BigDecimal
The truncated value.
TryFormat(Span<byte>, out int, ReadOnlySpan<char>, IFormatProvider?)
Tries to format the value of the current instance as UTF-8 into the provided span of bytes.
public bool TryFormat(Span<byte> utf8Destination, out int bytesWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
utf8DestinationSpan<byte>The span in which to write this instance's value formatted as a span of bytes.
bytesWrittenintWhen this method returns, contains the number of bytes that were written in
utf8Destination.formatReadOnlySpan<char>A span containing the characters that represent a standard or custom format string that defines the acceptable format for
utf8Destination.providerIFormatProviderAn optional object that supplies culture-specific formatting information for
utf8Destination.
Returns
TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)
Tries to format the value of the current instance into the provided span of characters.
public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
destinationSpan<char>The span in which to write this instance's value formatted as a span of characters.
charsWrittenintWhen this method returns, contains the number of characters that were written in
destination.formatReadOnlySpan<char>A span containing the characters that represent a standard or custom format string that defines the acceptable format for
destination.providerIFormatProviderAn optional object that supplies culture-specific formatting information for
destination.
Returns
TryParse(string?, out BigDecimal)
Attempts to parse the decimal text representation of a value using the current culture.
public static bool TryParse(string? s, out BigDecimal result)
Parameters
sstringThe text to parse.
resultBigDecimalWhen this method returns, contains the parsed value, or zero on failure.
Returns
TryToDecimal(out decimal)
Attempts to convert the value to a decimal.
public bool TryToDecimal(out decimal result)
Parameters
resultdecimalWhen this method returns, contains the converted value, or zero on failure.
Returns
TryToDouble(out double)
Attempts to convert the value to the nearest double.
public bool TryToDouble(out double result)
Parameters
resultdoubleWhen this method returns, contains the converted value, or zero on failure.
Returns
Operators
explicit operator decimal(BigDecimal)
Explicitly converts a BigDecimal to a decimal.
public static explicit operator decimal(BigDecimal value)
Parameters
valueBigDecimalThe value to convert.
Returns
Exceptions
- OverflowException
valueis outside the range of decimal.
explicit operator double(BigDecimal)
Explicitly converts a BigDecimal to the nearest double.
public static explicit operator double(BigDecimal value)
Parameters
valueBigDecimalThe value to convert.
Returns
explicit operator BigInteger(BigDecimal)
Explicitly converts a BigDecimal to a BigInteger, truncating toward zero.
public static explicit operator BigInteger(BigDecimal value)
Parameters
valueBigDecimalThe value to convert.
Returns
- BigInteger
The integer part of
value.
explicit operator BigDecimal(double)
Explicitly converts a double to a BigDecimal via its shortest round-trip decimal
text - so 0.1d becomes 0.1, not its exact binary expansion.
public static explicit operator BigDecimal(double value)
Parameters
valuedoubleThe value to convert.
Returns
- BigDecimal
The decimal value.
Exceptions
- ArgumentException
valueis not a finite number.
implicit operator BigDecimal(decimal)
Implicitly converts a decimal to a BigDecimal exactly.
public static implicit operator BigDecimal(decimal value)
Parameters
valuedecimalThe decimal value.
Returns
- BigDecimal
The exact decimal value.
implicit operator BigDecimal(int)
Implicitly converts a 32-bit signed integer to a BigDecimal.
public static implicit operator BigDecimal(int value)
Parameters
valueintThe integer value.
Returns
- BigDecimal
The exact decimal value.
implicit operator BigDecimal(long)
Implicitly converts a 64-bit signed integer to a BigDecimal.
public static implicit operator BigDecimal(long value)
Parameters
valuelongThe integer value.
Returns
- BigDecimal
The exact decimal value.
implicit operator BigDecimal(BigInteger)
Implicitly converts a BigInteger to a BigDecimal.
public static implicit operator BigDecimal(BigInteger value)
Parameters
valueBigIntegerThe integer value.
Returns
- BigDecimal
The exact decimal value.
Explicit Interface Implementations
One
Gets a BigDecimal representing the value one.
static BigDecimal One { get; }
Returns
- BigDecimal
The value
1.
Parse(ReadOnlySpan<byte>, IFormatProvider?)
Parses the UTF-8 decimal text representation of a value.
static BigDecimal Parse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider)
Parameters
utf8TextReadOnlySpan<byte>The UTF-8 text to parse.
providerIFormatProviderThe format provider supplying the decimal separator and sign symbols.
Returns
- BigDecimal
The parsed value.
Exceptions
- FormatException
utf8Textis not a valid decimal representation.
Parse(ReadOnlySpan<char>, IFormatProvider?)
Parses the decimal text representation of a value from a character span.
static BigDecimal Parse(ReadOnlySpan<char> s, IFormatProvider? provider)
Parameters
sReadOnlySpan<char>The text to parse.
providerIFormatProviderThe format provider supplying the decimal separator and sign symbols.
Returns
- BigDecimal
The parsed value.
Exceptions
- FormatException
sis not a valid decimal representation.
Parse(string, IFormatProvider?)
Parses the decimal text representation of a value using the specified format provider.
static BigDecimal Parse(string s, IFormatProvider? provider)
Parameters
sstringThe text to parse.
providerIFormatProviderThe format provider supplying the decimal separator and sign symbols.
Returns
- BigDecimal
The parsed value.
Exceptions
- ArgumentNullException
sis null.- FormatException
sis not a valid decimal representation.
IAdditiveIdentity<BigDecimal, BigDecimal>.AdditiveIdentity
Gets the additive identity of the current type.
static BigDecimal IAdditiveIdentity<BigDecimal, BigDecimal>.AdditiveIdentity { get; }
Returns
IMultiplicativeIdentity<BigDecimal, BigDecimal>.MultiplicativeIdentity
Gets the multiplicative identity of the current type.
static BigDecimal IMultiplicativeIdentity<BigDecimal, BigDecimal>.MultiplicativeIdentity { get; }
Returns
INumberBase<BigDecimal>.Abs(BigDecimal)
Computes the absolute of a value.
static BigDecimal INumberBase<BigDecimal>.Abs(BigDecimal value)
Parameters
valueBigDecimalThe value for which to get its absolute.
Returns
- BigDecimal
The absolute of
value.
Exceptions
- OverflowException
The absolute of
valueis not representable by BigDecimal.
INumberBase<BigDecimal>.IsCanonical(BigDecimal)
Determines if a value is in its canonical representation.
static bool INumberBase<BigDecimal>.IsCanonical(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.IsComplexNumber(BigDecimal)
Determines if a value represents a complex number.
static bool INumberBase<BigDecimal>.IsComplexNumber(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.IsEvenInteger(BigDecimal)
Determines if a value represents an even integral number.
static bool INumberBase<BigDecimal>.IsEvenInteger(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.IsFinite(BigDecimal)
Determines if a value is finite.
static bool INumberBase<BigDecimal>.IsFinite(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.IsImaginaryNumber(BigDecimal)
Determines if a value represents a pure imaginary number.
static bool INumberBase<BigDecimal>.IsImaginaryNumber(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.IsInfinity(BigDecimal)
Determines if a value is infinite.
static bool INumberBase<BigDecimal>.IsInfinity(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.IsInteger(BigDecimal)
Determines if a value represents an integral number.
static bool INumberBase<BigDecimal>.IsInteger(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.IsNaN(BigDecimal)
Determines if a value is NaN.
static bool INumberBase<BigDecimal>.IsNaN(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.IsNegative(BigDecimal)
Determines if a value represents a negative real number.
static bool INumberBase<BigDecimal>.IsNegative(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.IsNegativeInfinity(BigDecimal)
Determines if a value is negative infinity.
static bool INumberBase<BigDecimal>.IsNegativeInfinity(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.IsNormal(BigDecimal)
Determines if a value is normal.
static bool INumberBase<BigDecimal>.IsNormal(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.IsOddInteger(BigDecimal)
Determines if a value represents an odd integral number.
static bool INumberBase<BigDecimal>.IsOddInteger(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.IsPositive(BigDecimal)
Determines if a value represents zero or a positive real number.
static bool INumberBase<BigDecimal>.IsPositive(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.IsPositiveInfinity(BigDecimal)
Determines if a value is positive infinity.
static bool INumberBase<BigDecimal>.IsPositiveInfinity(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.IsRealNumber(BigDecimal)
Determines if a value represents a real number.
static bool INumberBase<BigDecimal>.IsRealNumber(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.IsSubnormal(BigDecimal)
Determines if a value is subnormal.
static bool INumberBase<BigDecimal>.IsSubnormal(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.IsZero(BigDecimal)
Determines if a value is zero.
static bool INumberBase<BigDecimal>.IsZero(BigDecimal value)
Parameters
valueBigDecimalThe value to be checked.
Returns
INumberBase<BigDecimal>.MaxMagnitude(BigDecimal, BigDecimal)
Compares two values to compute which has the greater magnitude.
static BigDecimal INumberBase<BigDecimal>.MaxMagnitude(BigDecimal x, BigDecimal y)
Parameters
xBigDecimalThe value to compare with
y.yBigDecimalThe value to compare with
x.
Returns
- BigDecimal
xif it has a greater magnitude thany; otherwise,y.
INumberBase<BigDecimal>.MaxMagnitudeNumber(BigDecimal, BigDecimal)
Compares two values to compute which has the greater magnitude and returning the other value if an input is NaN.
static BigDecimal INumberBase<BigDecimal>.MaxMagnitudeNumber(BigDecimal x, BigDecimal y)
Parameters
xBigDecimalThe value to compare with
y.yBigDecimalThe value to compare with
x.
Returns
- BigDecimal
xif it has a greater magnitude thany; otherwise,y.
INumberBase<BigDecimal>.MinMagnitude(BigDecimal, BigDecimal)
Compares two values to compute which has the lesser magnitude.
static BigDecimal INumberBase<BigDecimal>.MinMagnitude(BigDecimal x, BigDecimal y)
Parameters
xBigDecimalThe value to compare with
y.yBigDecimalThe value to compare with
x.
Returns
- BigDecimal
xif it has a lesser magnitude thany; otherwise,y.
INumberBase<BigDecimal>.MinMagnitudeNumber(BigDecimal, BigDecimal)
Compares two values to compute which has the lesser magnitude and returning the other value if an input is NaN.
static BigDecimal INumberBase<BigDecimal>.MinMagnitudeNumber(BigDecimal x, BigDecimal y)
Parameters
xBigDecimalThe value to compare with
y.yBigDecimalThe value to compare with
x.
Returns
- BigDecimal
xif it has a lesser magnitude thany; otherwise,y.
INumberBase<BigDecimal>.Parse(ReadOnlySpan<char>, NumberStyles, IFormatProvider)
Parses a span of characters into a value.
static BigDecimal INumberBase<BigDecimal>.Parse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider)
Parameters
sReadOnlySpan<char>The span of characters to parse.
styleNumberStylesA bitwise combination of number styles that can be present in
s.providerIFormatProviderAn object that provides culture-specific formatting information about
s.
Returns
- BigDecimal
The result of parsing
s.
Exceptions
- ArgumentException
styleis not a supported NumberStyles value.- FormatException
sis not in the correct format.- OverflowException
sis not representable by BigDecimal.
INumberBase<BigDecimal>.Parse(string, NumberStyles, IFormatProvider)
Parses a string into a value.
static BigDecimal INumberBase<BigDecimal>.Parse(string s, NumberStyles style, IFormatProvider provider)
Parameters
sstringThe string to parse.
styleNumberStylesA bitwise combination of number styles that can be present in
s.providerIFormatProviderAn object that provides culture-specific formatting information about
s.
Returns
- BigDecimal
The result of parsing
s.
Exceptions
- ArgumentException
styleis not a supported NumberStyles value.- ArgumentNullException
sis null.- FormatException
sis not in the correct format.- OverflowException
sis not representable by BigDecimal.
INumberBase<BigDecimal>.Radix
Gets the radix, or base, for the type.
static int INumberBase<BigDecimal>.Radix { get; }
Returns
INumberBase<BigDecimal>.TryConvertFromChecked<TOther>(TOther, out BigDecimal)
Tries to convert a value to an instance of the the current type, throwing an overflow exception for any values that fall outside the representable range of the current type.
static bool INumberBase<BigDecimal>.TryConvertFromChecked<TOther>(TOther value, out BigDecimal result) where TOther : INumberBase<TOther>
Parameters
valueTOtherThe value that's used to create the instance of BigDecimal.
resultBigDecimalWhen this method returns, contains an instance of BigDecimal converted from
value.
Returns
Type Parameters
TOtherThe type of
value.
Exceptions
- OverflowException
valueis not representable by BigDecimal.
INumberBase<BigDecimal>.TryConvertFromSaturating<TOther>(TOther, out BigDecimal)
Tries to convert a value to an instance of the the current type, saturating any values that fall outside the representable range of the current type.
static bool INumberBase<BigDecimal>.TryConvertFromSaturating<TOther>(TOther value, out BigDecimal result) where TOther : INumberBase<TOther>
Parameters
valueTOtherThe value that is used to create the instance of BigDecimal.
resultBigDecimalWhen this method returns, contains an instance of BigDecimal converted from
value.
Returns
Type Parameters
TOtherThe type of
value.
INumberBase<BigDecimal>.TryConvertFromTruncating<TOther>(TOther, out BigDecimal)
Tries to convert a value to an instance of the the current type, truncating any values that fall outside the representable range of the current type.
static bool INumberBase<BigDecimal>.TryConvertFromTruncating<TOther>(TOther value, out BigDecimal result) where TOther : INumberBase<TOther>
Parameters
valueTOtherThe value that is used to create the instance of BigDecimal.
resultBigDecimalWhen this method returns, contains an instance of BigDecimal converted from
value.
Returns
Type Parameters
TOtherThe type of
value.
INumberBase<BigDecimal>.TryConvertToChecked<TOther>(BigDecimal, out TOther)
Tries to convert an instance of the the current type to another type, throwing an overflow exception for any values that fall outside the representable range of the current type.
static bool INumberBase<BigDecimal>.TryConvertToChecked<TOther>(BigDecimal value, out TOther result) where TOther : INumberBase<TOther>
Parameters
valueBigDecimalThe value that is used to create the instance of
TOther.resultTOtherWhen this method returns, contains an instance of
TOtherconverted fromvalue.
Returns
Type Parameters
TOtherThe type to which
valueshould be converted.
Exceptions
- OverflowException
valueis not representable byTOther.
INumberBase<BigDecimal>.TryConvertToSaturating<TOther>(BigDecimal, out TOther)
Tries to convert an instance of the the current type to another type, saturating any values that fall outside the representable range of the current type.
static bool INumberBase<BigDecimal>.TryConvertToSaturating<TOther>(BigDecimal value, out TOther result) where TOther : INumberBase<TOther>
Parameters
valueBigDecimalThe value that is used to create the instance of
TOther.resultTOtherWhen this method returns, contains an instance of
TOtherconverted fromvalue.
Returns
Type Parameters
TOtherThe type to which
valueshould be converted.
INumberBase<BigDecimal>.TryConvertToTruncating<TOther>(BigDecimal, out TOther)
Tries to convert an instance of the the current type to another type, truncating any values that fall outside the representable range of the current type.
static bool INumberBase<BigDecimal>.TryConvertToTruncating<TOther>(BigDecimal value, out TOther result) where TOther : INumberBase<TOther>
Parameters
valueBigDecimalThe value that is used to create the instance of
TOther.resultTOtherWhen this method returns, contains an instance of
TOtherconverted fromvalue.
Returns
Type Parameters
TOtherThe type to which
valueshould be converted.
INumberBase<BigDecimal>.TryParse(ReadOnlySpan<char>, NumberStyles, IFormatProvider, out BigDecimal)
Tries to parse a span of characters into a value.
static bool INumberBase<BigDecimal>.TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatProvider provider, out BigDecimal result)
Parameters
sReadOnlySpan<char>The span of characters to parse.
styleNumberStylesA bitwise combination of number styles that can be present in
s.providerIFormatProviderAn object that provides culture-specific formatting information about
s.resultBigDecimalOn return, contains the result of succesfully parsing
sor an undefined value on failure.
Returns
Exceptions
- ArgumentException
styleis not a supported NumberStyles value.
INumberBase<BigDecimal>.TryParse(string, NumberStyles, IFormatProvider, out BigDecimal)
Tries to parse a string into a value.
static bool INumberBase<BigDecimal>.TryParse(string s, NumberStyles style, IFormatProvider provider, out BigDecimal result)
Parameters
sstringThe string to parse.
styleNumberStylesA bitwise combination of number styles that can be present in
s.providerIFormatProviderAn object that provides culture-specific formatting information about
s.resultBigDecimalOn return, contains the result of succesfully parsing
sor an undefined value on failure.
Returns
Exceptions
- ArgumentException
styleis not a supported NumberStyles value.
INumber<BigDecimal>.Clamp(BigDecimal, BigDecimal, BigDecimal)
Clamps a value to an inclusive minimum and maximum value.
static BigDecimal INumber<BigDecimal>.Clamp(BigDecimal value, BigDecimal min, BigDecimal max)
Parameters
valueBigDecimalThe value to clamp.
minBigDecimalThe inclusive minimum to which
valueshould clamp.maxBigDecimalThe inclusive maximum to which
valueshould clamp.
Returns
- BigDecimal
The result of clamping
valueto the inclusive range ofminandmax.
Exceptions
- ArgumentException
minis greater thanmax.
INumber<BigDecimal>.CopySign(BigDecimal, BigDecimal)
Copies the sign of a value to the sign of another value.
static BigDecimal INumber<BigDecimal>.CopySign(BigDecimal value, BigDecimal sign)
Parameters
valueBigDecimalThe value whose magnitude is used in the result.
signBigDecimalThe value whose sign is used in the result.
Returns
- BigDecimal
A value with the magnitude of
valueand the sign ofsign.
INumber<BigDecimal>.Max(BigDecimal, BigDecimal)
Compares two values to compute which is greater.
static BigDecimal INumber<BigDecimal>.Max(BigDecimal x, BigDecimal y)
Parameters
xBigDecimalThe value to compare with
y.yBigDecimalThe value to compare with
x.
Returns
- BigDecimal
xif it is greater thany; otherwise,y.
INumber<BigDecimal>.MaxNumber(BigDecimal, BigDecimal)
Compares two values to compute which is greater and returning the other value if an input is NaN.
static BigDecimal INumber<BigDecimal>.MaxNumber(BigDecimal x, BigDecimal y)
Parameters
xBigDecimalThe value to compare with
y.yBigDecimalThe value to compare with
x.
Returns
- BigDecimal
xif it is greater thany; otherwise,y.
INumber<BigDecimal>.Min(BigDecimal, BigDecimal)
Compares two values to compute which is lesser.
static BigDecimal INumber<BigDecimal>.Min(BigDecimal x, BigDecimal y)
Parameters
xBigDecimalThe value to compare with
y.yBigDecimalThe value to compare with
x.
Returns
- BigDecimal
xif it is less thany; otherwise,y.
INumber<BigDecimal>.MinNumber(BigDecimal, BigDecimal)
Compares two values to compute which is lesser and returning the other value if an input is NaN.
static BigDecimal INumber<BigDecimal>.MinNumber(BigDecimal x, BigDecimal y)
Parameters
xBigDecimalThe value to compare with
y.yBigDecimalThe value to compare with
x.
Returns
- BigDecimal
xif it is less thany; otherwise,y.
INumber<BigDecimal>.Sign(BigDecimal)
Computes the sign of a value.
static int INumber<BigDecimal>.Sign(BigDecimal value)
Parameters
valueBigDecimalThe value whose sign is to be computed.
Returns
- int
A positive value if
valueis positive,0ifvalueis zero, and a negative value ifvalueis negative.
ISignedNumber<BigDecimal>.NegativeOne
Gets the value -1 for the type.
static BigDecimal ISignedNumber<BigDecimal>.NegativeOne { get; }
Returns
TryParse(ReadOnlySpan<byte>, IFormatProvider?, out BigDecimal)
Attempts to parse the UTF-8 decimal text representation of a value.
static bool TryParse(ReadOnlySpan<byte> utf8Text, IFormatProvider? provider, out BigDecimal result)
Parameters
utf8TextReadOnlySpan<byte>The UTF-8 text to parse.
providerIFormatProviderThe format provider supplying the decimal separator and sign symbols.
resultBigDecimalWhen this method returns, contains the parsed value, or zero on failure.
Returns
TryParse(ReadOnlySpan<char>, IFormatProvider?, out BigDecimal)
Attempts to parse the decimal text representation of a value from a character span.
static bool TryParse(ReadOnlySpan<char> s, IFormatProvider? provider, out BigDecimal result)
Parameters
sReadOnlySpan<char>The text to parse.
providerIFormatProviderThe format provider supplying the decimal separator and sign symbols.
resultBigDecimalWhen this method returns, contains the parsed value, or zero on failure.
Returns
TryParse(string?, IFormatProvider?, out BigDecimal)
Attempts to parse the decimal text representation of a value.
static bool TryParse(string? s, IFormatProvider? provider, out BigDecimal result)
Parameters
sstringThe text to parse.
providerIFormatProviderThe format provider supplying the decimal separator and sign symbols.
resultBigDecimalWhen this method returns, contains the parsed value, or zero on failure.
Returns
Zero
Gets a BigDecimal representing the value zero.
static BigDecimal Zero { get; }
Returns
- BigDecimal
The value
0.
operator +(BigDecimal, BigDecimal)
Adds two values exactly.
static BigDecimal operator +(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe first value.
rightBigDecimalThe second value.
Returns
- BigDecimal
The exact sum.
operator --(BigDecimal)
Decrements a value by one.
static BigDecimal operator --(BigDecimal value)
Parameters
valueBigDecimalThe value to decrement.
Returns
- BigDecimal
The value minus one.
operator /(BigDecimal, BigDecimal)
Divides one value by another, rounding to DefaultDivisionScale decimal places.
static BigDecimal operator /(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe dividend.
rightBigDecimalThe divisor.
Returns
- BigDecimal
The rounded quotient.
Exceptions
- DivideByZeroException
rightis zero.
operator ==(BigDecimal, BigDecimal)
Determines whether two values are numerically equal.
static bool operator ==(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe first value.
rightBigDecimalThe second value.
Returns
operator >(BigDecimal, BigDecimal)
Determines whether one value is greater than another.
static bool operator >(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe first value.
rightBigDecimalThe second value.
Returns
operator >=(BigDecimal, BigDecimal)
Determines whether one value is greater than or equal to another.
static bool operator >=(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe first value.
rightBigDecimalThe second value.
Returns
operator ++(BigDecimal)
Increments a value by one.
static BigDecimal operator ++(BigDecimal value)
Parameters
valueBigDecimalThe value to increment.
Returns
- BigDecimal
The value plus one.
operator !=(BigDecimal, BigDecimal)
Determines whether two values are not numerically equal.
static bool operator !=(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe first value.
rightBigDecimalThe second value.
Returns
operator <(BigDecimal, BigDecimal)
Determines whether one value is less than another.
static bool operator <(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe first value.
rightBigDecimalThe second value.
Returns
operator <=(BigDecimal, BigDecimal)
Determines whether one value is less than or equal to another.
static bool operator <=(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe first value.
rightBigDecimalThe second value.
Returns
operator %(BigDecimal, BigDecimal)
Returns the remainder of dividing one value by another.
static BigDecimal operator %(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe dividend.
rightBigDecimalThe divisor.
Returns
- BigDecimal
The exact remainder.
Exceptions
- DivideByZeroException
rightis zero.
operator *(BigDecimal, BigDecimal)
Multiplies two values exactly.
static BigDecimal operator *(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe first value.
rightBigDecimalThe second value.
Returns
- BigDecimal
The exact product.
operator -(BigDecimal, BigDecimal)
Subtracts one value from another exactly.
static BigDecimal operator -(BigDecimal left, BigDecimal right)
Parameters
leftBigDecimalThe value to subtract from.
rightBigDecimalThe value to subtract.
Returns
- BigDecimal
The exact difference.
operator -(BigDecimal)
Negates a value.
static BigDecimal operator -(BigDecimal value)
Parameters
valueBigDecimalThe value to negate.
Returns
- BigDecimal
The additive inverse of
value.
operator +(BigDecimal)
Returns the value unchanged.
static BigDecimal operator +(BigDecimal value)
Parameters
valueBigDecimalThe value.
Returns
- BigDecimal
The same value.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |