# Struct bigdecimal::BigDecimal [−][src]

`pub struct BigDecimal { /* fields omitted */ }`

## Expand description

A big decimal type.

## Implementations

Creates and initializes a `BigDecimal`

.

Creates and initializes a `BigDecimal`

.

Decodes using `str::from_utf8`

and forwards to `BigDecimal::from_str_radix`

.
Only base-10 is supported.

# Examples

```
use bigdecimal::{BigDecimal, Zero};
assert_eq!(BigDecimal::parse_bytes(b"0", 10).unwrap(), BigDecimal::zero());
assert_eq!(BigDecimal::parse_bytes(b"13", 10).unwrap(), BigDecimal::from(13));
```

Return a new BigDecimal object equivalent to self, with internal scaling set to the number specified. If the new_scale is lower than the current value (indicating a larger power of 10), digits will be dropped (as precision is lower)

Return a new BigDecimal object with precision set to new value

Return the sign of the `BigDecimal`

as `num::bigint::Sign`

.

# Examples

```
extern crate num_bigint;
extern crate bigdecimal;
use std::str::FromStr;
assert_eq!(bigdecimal::BigDecimal::from_str("-1").unwrap().sign(), num_bigint::Sign::Minus);
assert_eq!(bigdecimal::BigDecimal::from_str("0").unwrap().sign(), num_bigint::Sign::NoSign);
assert_eq!(bigdecimal::BigDecimal::from_str("1").unwrap().sign(), num_bigint::Sign::Plus);
```

Return the internal big integer value and an exponent. Note that a positive exponent indicates a negative power of 10.

# Examples

```
extern crate num_bigint;
extern crate bigdecimal;
use std::str::FromStr;
assert_eq!(bigdecimal::BigDecimal::from_str("1.1").unwrap().as_bigint_and_exponent(),
(num_bigint::BigInt::from_str("11").unwrap(), 1));
```

Convert into the internal big integer value and an exponent. Note that a positive exponent indicates a negative power of 10.

# Examples

```
extern crate num_bigint;
extern crate bigdecimal;
use std::str::FromStr;
assert_eq!(bigdecimal::BigDecimal::from_str("1.1").unwrap().into_bigint_and_exponent(),
(num_bigint::BigInt::from_str("11").unwrap(), 1));
```

Compute the absolute value of number

Divide this efficiently by 2

Note, if this is odd, the precision will increase by 1, regardless of the context’s limit.

Take the square root of the number

If the value is < 0, None is returned

Take the cube root of the number

Compute the reciprical of the number: x^{-1}

Return number rounded to round_digits precision after the decimal point

Return true if this number has zero fractional part (is equal to an integer)

Evaluate the natural-exponential function e^{x}

## Trait Implementations

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `+`

operator.

Performs the `+`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `+`

operator.

Performs the `+`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `+`

operator.

Performs the `+`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `+`

operator.

Performs the `+`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `+`

operator.

Performs the `+`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `+`

operator.

Performs the `+`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `+`

operator.

Performs the `+`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `+`

operator.

Performs the `+`

operation. Read more

Performs the `+=`

operation. Read more

Performs the `+=`

operation. Read more

Performs the `+=`

operation. Read more

Performs the `+=`

operation. Read more

Returns the “default value” for a type. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `/`

operator.

Performs the `/`

operation. Read more

Converts an `i64`

to return an optional value of this type. If the
value cannot be represented by this type, then `None`

is returned. Read more

Converts an `u64`

to return an optional value of this type. If the
value cannot be represented by this type, then `None`

is returned. Read more

Converts a `f32`

to return an optional value of this type. If the
value cannot be represented by this type, then `None`

is returned. Read more

Converts a `f64`

to return an optional value of this type. If the
value cannot be represented by this type, then `None`

is returned. Read more

Converts an `isize`

to return an optional value of this type. If the
value cannot be represented by this type, then `None`

is returned. Read more

Converts an `i8`

to return an optional value of this type. If the
value cannot be represented by this type, then `None`

is returned. Read more

Converts an `i16`

to return an optional value of this type. If the
value cannot be represented by this type, then `None`

is returned. Read more

Converts an `i32`

to return an optional value of this type. If the
value cannot be represented by this type, then `None`

is returned. Read more

Converts an `i128`

to return an optional value of this type. If the
value cannot be represented by this type, then `None`

is returned. Read more

Converts a `usize`

to return an optional value of this type. If the
value cannot be represented by this type, then `None`

is returned. Read more

Converts an `u8`

to return an optional value of this type. If the
value cannot be represented by this type, then `None`

is returned. Read more

Converts an `u16`

to return an optional value of this type. If the
value cannot be represented by this type, then `None`

is returned. Read more

Converts an `u32`

to return an optional value of this type. If the
value cannot be represented by this type, then `None`

is returned. Read more

#### type Err = ParseBigDecimalError

#### type Err = ParseBigDecimalError

The associated error which can be returned from parsing.

Parses a string `s`

to return a value of this type. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `*`

operator.

Performs the `*`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `*`

operator.

Performs the `*`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `*`

operator.

Performs the `*`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `*`

operator.

Performs the `*`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `*`

operator.

Performs the `*`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `*`

operator.

Performs the `*`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `*`

operator.

Performs the `*`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `*`

operator.

Performs the `*`

operation. Read more

Performs the `*=`

operation. Read more

Performs the `*=`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `-`

operator.

Performs the unary `-`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `-`

operator.

Performs the unary `-`

operation. Read more

Creates and initializes a BigDecimal.

Returns the multiplicative identity element of `Self`

, `1`

. Read more

Complete ordering implementation for BigDecimal

# Example

```
use std::str::FromStr;
let a = bigdecimal::BigDecimal::from_str("-1").unwrap();
let b = bigdecimal::BigDecimal::from_str("1").unwrap();
assert!(a < b);
assert!(b > a);
let c = bigdecimal::BigDecimal::from_str("1").unwrap();
assert!(b >= c);
assert!(c >= b);
let d = bigdecimal::BigDecimal::from_str("10.0").unwrap();
assert!(d > c);
let e = bigdecimal::BigDecimal::from_str(".5").unwrap();
assert!(e < c);
```

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

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

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `%`

operator.

Performs the `%`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `%`

operator.

Performs the `%`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `%`

operator.

Performs the `%`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `%`

operator.

Performs the `%`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `-`

operator.

Performs the `-`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `-`

operator.

Performs the `-`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `-`

operator.

Performs the `-`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `-`

operator.

Performs the `-`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `-`

operator.

Performs the `-`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `-`

operator.

Performs the `-`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `-`

operator.

Performs the `-`

operation. Read more

#### type Output = BigDecimal

#### type Output = BigDecimal

The resulting type after applying the `-`

operator.

Performs the `-`

operation. Read more

Performs the `-=`

operation. Read more

Performs the `-=`

operation. Read more

Performs the `-=`

operation. Read more

Performs the `-=`

operation. Read more

Method which takes an iterator and generates `Self`

from the elements by
“summing up” the items. Read more

Method which takes an iterator and generates `Self`

from the elements by
“summing up” the items. Read more

Converts the value of `self`

to an `i64`

. If the value cannot be
represented by an `i64`

, then `None`

is returned. Read more

Converts the value of `self`

to a `u64`

. If the value cannot be
represented by a `u64`

, then `None`

is returned. Read more

Converts the value of `self`

to an `f64`

. Overflows may map to positive
or negative inifinity, otherwise `None`

is returned if the value cannot
be represented by an `f64`

. Read more

Converts the value of `self`

to an `isize`

. If the value cannot be
represented by an `isize`

, then `None`

is returned. Read more

Converts the value of `self`

to an `i8`

. If the value cannot be
represented by an `i8`

, then `None`

is returned. Read more

Converts the value of `self`

to an `i16`

. If the value cannot be
represented by an `i16`

, then `None`

is returned. Read more

Converts the value of `self`

to an `i32`

. If the value cannot be
represented by an `i32`

, then `None`

is returned. Read more

Converts the value of `self`

to an `i128`

. If the value cannot be
represented by an `i128`

(`i64`

under the default implementation), then
`None`

is returned. Read more

Converts the value of `self`

to a `usize`

. If the value cannot be
represented by a `usize`

, then `None`

is returned. Read more

Converts the value of `self`

to a `u8`

. If the value cannot be
represented by a `u8`

, then `None`

is returned. Read more

Converts the value of `self`

to a `u16`

. If the value cannot be
represented by a `u16`

, then `None`

is returned. Read more

Converts the value of `self`

to a `u32`

. If the value cannot be
represented by a `u32`

, then `None`

is returned. Read more

Converts the value of `self`

to a `u128`

. If the value cannot be
represented by a `u128`

(`u64`

under the default implementation), then
`None`

is returned. Read more

## Auto Trait Implementations

### impl RefUnwindSafe for BigDecimal

### impl Send for BigDecimal

### impl Sync for BigDecimal

### impl Unpin for BigDecimal

### impl UnwindSafe for BigDecimal

## Blanket Implementations

Mutably borrows from an owned value. Read more