pub struct Decimal { /* private fields */ }
Expand description

An arbitrary-precision Decimal type with a distinct representation of negative zero (-0).

Implementations

Constructs a new Decimal with the provided components. The value of the decimal is (coefficient * 10^exponent) * (if sign == Sign::Negative { -1 } else { 1 })

Returns scale of the Decimal value If zero or positive, a scale indicates the number of digits to the right of the decimal point. If negative, the unscaled value of the number is multiplied by ten to the power of the negation of the scale. For example, a scale of -3 means the unscaled value is multiplied by 1000.

Returns the number of digits in the non-scaled integer representation of the decimal.

Constructs a Decimal with the value -0d0. This is provided as a convenience method because Rust will ignore a unary minus when it is applied to an zero literal (-0).

Constructs a Decimal with a coefficient of -0 and the specified exponent. This function is provided as a convenience method because Rust will ignore a unary minus when it is applied to a zero literal (-0).

Returns true if this Decimal is a zero of any sign or exponent.

Returns true if this Decimal’s coefficient has a negative sign AND a magnitude greater than zero. Otherwise, returns false. (Negative zero returns false.)

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Make a Decimal from a BigDecimal. This is a lossless operation.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

Converts to this type from the input type.

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Attempts to create a BigDecimal from a Decimal. Returns an Error if the Decimal being converted is a negative zero, which BigDecimal cannot represent. Returns Ok otherwise.

The type returned in the event of a conversion error.

The type returned in the event of a conversion error.

Performs the conversion.

Attempts to create a Decimal from an f64. Returns an Error if the f64 being converted is a special value, including:

  • Infinity
  • Negative infinity
  • NaN (not-a-number) Otherwise, returns Ok.

Because Decimal can represent negative zero, f64::neg_zero() IS supported.

NOTE: While the resulting decimal will be a very close approximation of the original f64’s value, this is an inherently lossy operation. Floating point values do not encode a precision. When converting an f64 to a Decimal, a precision for the new Decimal must be chosen somewhat arbitrarily. Do NOT rely on the precision of the resulting Decimal. This implementation may change without notice.

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.