[]Struct sqlx::types::BigDecimal

pub struct BigDecimal { /* fields omitted */ }

A big decimal type.

Implementations

impl BigDecimal

pub fn new(digits: BigInt, scale: i64) -> BigDecimal

Creates and initializes a BigDecimal.

pub fn parse_bytes(buf: &[u8], radix: u32) -> Option<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));

pub fn with_scale(&self, new_scale: i64) -> BigDecimal

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)

pub fn with_prec(&self, prec: u64) -> BigDecimal

Return a new BigDecimal object with precision set to new value

pub fn sign(&self) -> Sign

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);

pub fn as_bigint_and_exponent(&self) -> (BigInt, i64)

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));

pub fn into_bigint_and_exponent(self) -> (BigInt, i64)

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));

pub fn digits(&self) -> u64

Number of digits in the non-scaled integer representation

pub fn abs(&self) -> BigDecimal

Compute the absolute value of number

pub fn double(&self) -> BigDecimal

pub fn half(&self) -> BigDecimal

Divide this efficiently by 2

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

pub fn square(&self) -> BigDecimal

pub fn cube(&self) -> BigDecimal

pub fn sqrt(&self) -> Option<BigDecimal>

Take the square root of the number

If the value is < 0, None is returned

pub fn cbrt(&self) -> BigDecimal

Take the cube root of the number

pub fn inverse(&self) -> BigDecimal

Compute the reciprical of the number: x-1

pub fn round(&self, round_digits: i64) -> BigDecimal

Return number rounded to round_digits precision after the decimal point

pub fn is_integer(&self) -> bool

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

pub fn exp(&self) -> BigDecimal

Evaluate the natural-exponential function ex

#[must_use]pub fn normalized(&self) -> BigDecimal

Trait Implementations

impl<'a> Add<&'a BigDecimal> for BigDecimal

type Output = BigDecimal

The resulting type after applying the + operator.

impl<'a> Add<&'a BigInt> for BigDecimal

type Output = BigDecimal

The resulting type after applying the + operator.

impl<'a, 'b> Add<&'a BigInt> for &'b BigDecimal

type Output = BigDecimal

The resulting type after applying the + operator.

impl<'a, 'b> Add<&'b BigDecimal> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the + operator.

impl Add<BigDecimal> for BigDecimal

type Output = BigDecimal

The resulting type after applying the + operator.

impl<'a> Add<BigDecimal> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the + operator.

impl Add<BigInt> for BigDecimal

type Output = BigDecimal

The resulting type after applying the + operator.

impl<'a> Add<BigInt> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the + operator.

impl<'a> AddAssign<&'a BigDecimal> for BigDecimal

impl<'a> AddAssign<&'a BigInt> for BigDecimal

impl AddAssign<BigDecimal> for BigDecimal

impl<'a> AddAssign<BigInt> for BigDecimal

impl Clone for BigDecimal

impl Debug for BigDecimal

impl<'_> Decode<'_, MySql> for BigDecimal[src]

impl<'_> Decode<'_, Postgres> for BigDecimal[src]

impl Default for BigDecimal

impl Display for BigDecimal

impl<'a> Div<&'a BigDecimal> for BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a, 'b> Div<&'b BigDecimal> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<BigDecimal> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl Div<BigDecimal> for BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<f32> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<f64> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<i16> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<i16> for BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<i32> for BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<i32> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<i64> for BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<i64> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<i8> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<i8> for BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<u16> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<u32> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<u64> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'a> Div<u8> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the / operator.

impl<'_> Encode<'_, MySql> for BigDecimal[src]

impl<'_> Encode<'_, Postgres> for BigDecimal[src]

Panics

If this BigDecimal cannot be represented by [PgNumeric].

impl Eq for BigDecimal

impl From<(BigInt, i64)> for BigDecimal

impl From<BigInt> for BigDecimal

impl From<i16> for BigDecimal

impl From<i32> for BigDecimal

impl From<i64> for BigDecimal

impl From<i8> for BigDecimal

impl From<u16> for BigDecimal

impl From<u32> for BigDecimal

impl From<u64> for BigDecimal

impl From<u8> for BigDecimal

impl FromPrimitive for BigDecimal

impl FromStr for BigDecimal

type Err = ParseBigDecimalError

The associated error which can be returned from parsing.

impl Hash for BigDecimal

impl<'a> Mul<&'a BigDecimal> for BigDecimal

type Output = BigDecimal

The resulting type after applying the * operator.

impl<'a> Mul<&'a BigInt> for BigDecimal

type Output = BigDecimal

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a BigInt> for &'b BigDecimal

type Output = BigDecimal

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'b BigDecimal> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the * operator.

impl<'a> Mul<BigDecimal> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the * operator.

impl Mul<BigDecimal> for BigDecimal

type Output = BigDecimal

The resulting type after applying the * operator.

impl Mul<BigInt> for BigDecimal

type Output = BigDecimal

The resulting type after applying the * operator.

impl<'a> Mul<BigInt> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the * operator.

impl<'a> MulAssign<&'a BigDecimal> for BigDecimal

impl MulAssign<BigDecimal> for BigDecimal

impl Neg for BigDecimal

type Output = BigDecimal

The resulting type after applying the - operator.

impl<'a> Neg for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the - operator.

impl Num for BigDecimal

type FromStrRadixErr = ParseBigDecimalError

pub fn from_str_radix(
    s: &str,
    radix: u32
) -> Result<BigDecimal, ParseBigDecimalError>

Creates and initializes a BigDecimal.

impl One for BigDecimal

impl Ord for BigDecimal

pub fn cmp(&self, other: &BigDecimal) -> Ordering

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);

impl PartialEq<BigDecimal> for BigDecimal

impl PartialOrd<BigDecimal> for BigDecimal

impl<'a> Rem<&'a BigDecimal> for BigDecimal

type Output = BigDecimal

The resulting type after applying the % operator.

impl<'a, 'b> Rem<&'b BigDecimal> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the % operator.

impl Rem<BigDecimal> for BigDecimal

type Output = BigDecimal

The resulting type after applying the % operator.

impl<'a> Rem<BigDecimal> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the % operator.

impl Signed for BigDecimal

impl StructuralEq for BigDecimal

impl<'a> Sub<&'a BigDecimal> for BigDecimal

type Output = BigDecimal

The resulting type after applying the - operator.

impl<'a> Sub<&'a BigInt> for BigDecimal

type Output = BigDecimal

The resulting type after applying the - operator.

impl<'a, 'b> Sub<&'a BigInt> for &'b BigDecimal

type Output = BigDecimal

The resulting type after applying the - operator.

impl<'a, 'b> Sub<&'b BigDecimal> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the - operator.

impl Sub<BigDecimal> for BigDecimal

type Output = BigDecimal

The resulting type after applying the - operator.

impl<'a> Sub<BigDecimal> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the - operator.

impl Sub<BigInt> for BigDecimal

type Output = BigDecimal

The resulting type after applying the - operator.

impl<'a> Sub<BigInt> for &'a BigDecimal

type Output = BigDecimal

The resulting type after applying the - operator.

impl<'a> SubAssign<&'a BigDecimal> for BigDecimal

impl<'a> SubAssign<&'a BigInt> for BigDecimal

impl SubAssign<BigDecimal> for BigDecimal

impl<'a> SubAssign<BigInt> for BigDecimal

impl<'a> Sum<&'a BigDecimal> for BigDecimal

impl Sum<BigDecimal> for BigDecimal

impl ToBigInt for BigDecimal

impl ToPrimitive for BigDecimal

impl TryFrom<PgNumeric> for BigDecimal[src]

type Error = Box<dyn Error + 'static + Sync + Send, Global>

The type returned in the event of a conversion error.

impl TryFrom<f32> for BigDecimal

type Error = ParseBigDecimalError

The type returned in the event of a conversion error.

impl TryFrom<f64> for BigDecimal

type Error = ParseBigDecimalError

The type returned in the event of a conversion error.

impl Type<MySql> for BigDecimal[src]

impl Type<Postgres> for BigDecimal[src]

impl Zero for BigDecimal

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> CallHasher for T where
    T: Hash

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<I> FromRadix10 for I where
    I: Zero + One + AddAssign<I> + MulAssign<I>, 

impl<I> FromRadix10Signed for I where
    I: Zero + One + AddAssign<I> + SubAssign<I> + MulAssign<I>, 

impl<I> FromRadix16 for I where
    I: Zero + One + AddAssign<I> + MulAssign<I>, 

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, Rhs, Output> NumOps<Rhs, Output> for T where
    T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>, 
[src]

impl<T> NumRef for T where
    T: Num + for<'r> NumOps<&'r T, T>, 
[src]

impl<T, Base> RefNum<Base> for T where
    T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,