Struct BigDecimal
Represents an arbitrary precision decimal.
Inherited Members
Namespace: Singulink.Numerics
Assembly: Singulink.Numerics.BigDecimal.dll
Syntax
public readonly struct BigDecimal : IComparable<BigDecimal>, IEquatable<BigDecimal>, IComparable, IFormattable
Remarks
All operations on BigDecimal values are exact except division in the case of a repeating decimal result. If the result of the division
cannot be exactly represented in decimal form then the largest of the dividend precision, divisor precision and the specified maximum extended precision
is used to represent the result. You can specify the maximum extended precision to use for each division operation by calling the Divide(BigDecimal, BigDecimal, Int32, RoundingMode) method or use the DivideExact(BigDecimal, BigDecimal) / TryDivideExact(BigDecimal, BigDecimal, out BigDecimal) methods for division operations that are expected to return exact results. The standard
division operator (/
) first attempts to do an exact division and falls back to extended precision division using MaxExtendedDivisionPrecision as the maximum extended precision parameter.
Addition and subtraction are fully commutitive and associative for all converted data types. This makes BigDecimal a great data type to store aggregate totals that can freely add and subtract values without accruing inaccuracies over time.
Conversions from floating-point types (Single/Double) default to Truncate mode in order to match the behavior of floating point to Decimal conversions, but there are several conversion modes available that are each suitable in different situations. You can use the FromSingle(Single, FloatConversion) or FromDouble(Double, FloatConversion) methods to specify a different conversion mode.
Constructors
Name | Description |
---|---|
BigDecimal(BigInteger, Int32) | Initializes a new instance of the BigDecimal struct. |
Properties
Name | Description |
---|---|
DecimalPlaces | Gets the number of digits that appear after the decimal point. |
IsOne | Gets a value indicating whether the current value is 1. |
IsZero | Gets a value indicating whether the current value is 0. |
MaxExtendedDivisionPrecision | Gets the maximum extended precision used by the division operator if the result is not exact (i.e. has repeating decimals). If the dividend or divisor precision is greater then that value is used instead. The current value is 50 but is subject to change. |
MinusOne | Gets a value representing negative one (-1). |
One | Gets a value representing one (1). |
Precision | Gets the precision of this value, i.e. the total number of digits it contains (excluding any leading/trailing zeros). Zero values have a precision of 1. |
Sign | Gets a number indicating the sign (negative, positive, or zero) of the current value. |
Zero | Gets a value representing zero (0). |
Methods
Name | Description |
---|---|
Abs(BigDecimal) | Gets the absolute value of the given value. |
Ceiling(BigDecimal) | Rounds up to the nearest integral value. |
CompareTo(BigDecimal) | Compares this to another BigDecimal. |
Divide(BigDecimal, BigDecimal, Int32, RoundingMode) | Performs a division operation using the specified maximum extended precision. |
DivideExact(BigDecimal, BigDecimal) | Performs a division operation that results in an exact decimal answer (i.e. no repeating decimals). |
Equals(BigDecimal) | Indicates whether this value and the specified other value are equal. |
Equals(Object) | Indicates whether this value and the specified object are equal. |
Floor(BigDecimal) | Rounds down to the nearest integral value. |
FromDouble(Double, FloatConversion) | Gets a BigDecimal representation of a Double value. |
FromSingle(Single, FloatConversion) | Gets a BigDecimal representation of a Single value. |
GetHashCode() | Returns the hash code for this value. |
IsEvenInteger(BigDecimal) | Determines whether a value represents an even integral value. |
IsInteger(BigDecimal) | Determines whether a value represents an integral value. |
IsNegative(BigDecimal) | Determines if a value is negative. |
IsOddInteger(BigDecimal) | Determines whether a value represents an odd integral value. |
IsPositive(BigDecimal) | Determines if a value is positive. |
MaxMagnitude(BigDecimal, BigDecimal) | Compares to values to compute which has a greater magnitude. |
MinMagnitude(BigDecimal, BigDecimal) | Compares to values to compute which has a lesser magnitude. |
Parse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider) | Converts the string representation of a number to its decimal equivalent. |
Parse(ReadOnlySpan<Char>, IFormatProvider) | Converts the string representation of a number to its decimal equivalent. |
Parse(String, NumberStyles, IFormatProvider) | Converts the string representation of a number to its decimal equivalent. |
Parse(String, IFormatProvider) | Converts the string representation of a number to its decimal equivalent. |
Pow(BigDecimal, Int32) | Returns the specified basis raised to the specified exponent. Exponent must be greater than or equal to 0. |
Pow10(Int32) | Returns ten (10) raised to the specified exponent. |
Round(BigDecimal, RoundingMode) | Rounds the value to the nearest integer using the given rounding mode. |
Round(BigDecimal, Int32, RoundingMode) | Rounds the value to the specified number of decimal places using the given rounding mode. |
RoundToPrecision(BigDecimal, Int32, RoundingMode) | Rounds the value to the specified precision using the given rounding mode. |
ToString() | Returns a full-precision decimal form string representation of this value using the current culture. |
ToString(IFormatProvider) | Returns a full-precision decimal form string representation of this value. |
ToString(String, IFormatProvider) | Returns a string representation of this value. |
Truncate(BigDecimal) | Discards any fractional digits, effectively rounding towards zero. |
TruncateToPrecision(BigDecimal, Int32) | Truncates the number to the given precision by removing any extra least significant digits. |
TryDivideExact(BigDecimal, BigDecimal, out BigDecimal) | Performs a division operation that results in an exact decimal answer (i.e. no repeating decimals). |
TryParse(ReadOnlySpan<Char>, out BigDecimal) | Converts the string representation of a number to its decimal equivalent. |
TryParse(ReadOnlySpan<Char>, NumberStyles, IFormatProvider, out BigDecimal) | Converts the string representation of a number to its decimal equivalent. |
TryParse(ReadOnlySpan<Char>, IFormatProvider, out BigDecimal) | Converts the string representation of a number to its decimal equivalent. |
TryParse(String, NumberStyles, IFormatProvider, out BigDecimal) | Converts the string representation of a number to its decimal equivalent. |
TryParse(String, IFormatProvider, out BigDecimal) | Converts the string representation of a number to its decimal equivalent. |
Operators
Explicit Interface Implementations
Name | Description |
---|---|
IComparable.CompareTo(Object) |