Function fraction::division::divide_to_string
source · pub fn divide_to_string<I>(
dividend: I,
divisor: I,
precision: usize,
trail_zeroes: bool,
) -> Result<String, DivisionError>where
I: Clone + GenericInteger,
Expand description
Divide a fraction into a String
WARNING: Negative numbers as arguments are not supported.
- Makes only one allocation for the resulting string
- Does not round the last digit
Calculates the resulting string length first, allocates it, then makes the division and puts the result into the preallocated string.
§Examples
use fraction::division::divide_to_string;
assert_eq! (divide_to_string(2, 4, 2, false).unwrap(), "0.5");
assert_eq! (divide_to_string(2, 4, 2, true).unwrap(), "0.50");
assert_eq! (divide_to_string(5, 7, 16, false).unwrap(), "0.7142857142857142");
assert_eq! (divide_to_string(1, 3, 3, false).unwrap(), "0.333");
assert_eq! (divide_to_string(1, 3, 3, true).unwrap(), "0.333");