[][src]Type Definition fraction::prelude::Decimal

type Decimal = GenericDecimal<u64, u8>;

Basic Decimal based on 2 u64 numbers and one u8 for precision. Able to keep up to 19 digits in the number (including both sides across the floating point).

Examples

use fraction::Decimal;

let one = Decimal::from(152.568);
let two = Decimal::from(328.76842);

assert_eq!(one + two, Decimal::from("481.33642"));
assert_eq!(two - one, Decimal::from("176.20042"));
assert_eq!(one * two, Decimal::from("50159.5403"));
assert_eq!(two / one, Decimal::from("2.15489"));
// the result takes the max precision (between 5 and 8 it goes with 8)
assert_eq!(two / one.set_precision(8), Decimal::from("2.15489761"))