Skip to main content

fmt_decimal

Function fmt_decimal 

Source
fn fmt_decimal(
    f: &mut Formatter<'_>,
    integer_part: u64,
    fractional_part: u32,
    divisor: u32,
    prefix: &str,
    postfix: &str,
) -> Result
Expand description

Formats a floating point number in decimal notation.

The number is given as the integer_part and a fractional part. The value of the fractional part is fractional_part / divisor. So integer_part = 3, fractional_part = 12 and divisor = 100 represents the number 3.012. Trailing zeros are omitted.

divisor must not be above 100_000_000. It also should be a power of 10, everything else doesn’t make sense. fractional_part has to be less than 10 * divisor!

A prefix and postfix may be added. The whole thing is padded to the formatter’s width, if specified.