fn format_float(number: f64) -> String {
    let fract = number.fract();
    let mut integer = number.trunc() as u64;

    let mut formatted = format!("{:.2}", fract);
    if integer == 0 {
        // Return with the leading 0
        return formatted;
    }
    // Strip the 0
    formatted = formatted[1..].to_string();

    loop {
        let remainder = integer % 1000;
        integer /= 1000;

        if integer == 0 {
            let mut new_str = format!("{:}", remainder);
            new_str.push_str(&formatted);
            formatted = new_str;
            break;
        }

        let mut new_str = format!(",{:03}", remainder);
        new_str.push_str(&formatted);
        formatted = new_str;
    }

    formatted
}
// Format f64 with US locale decimal separators
// We don't care about speed or efficiency here
// Assumes that f64 in this context is always smaller than u64::MAX and larger than 0
Format f64 with US locale decimal separators
We don't care about speed or efficiency here
Assumes that f64 in this context is always smaller than u64::MAX and larger than 0
Format f64 with US locale decimal separators We don ' t care about speed or efficiency here Assumes that f64 in this context is always smaller than u64 :: MAX and larger than 0
fn format_float(number: f64) -> String {
    let fract = number.fract();
    let mut integer = number.trunc() as u64;
    let mut formatted = format!("{:.2}", fract);
    if integer == 0 {
        // Return with the leading 0
        return formatted;
    }
    // Strip the 0
    formatted = formatted[1..].to_string();
    loop {
        let remainder = integer % 1000;
        integer /= 1000;
        if integer == 0 {
            let mut new_str = format!("{:}", remainder);
            new_str.push_str(&formatted);
            formatted = new_str;
            break;
        }
        let mut new_str = format!(",{:03}", remainder);
        new_str.push_str(&formatted);
        formatted = new_str;
    }
    formatted
}
fn format_float ( number : f64 ) -> String { let fract = number . fract ( ) ; let mut integer = number . trunc ( ) as u64 ; let mut formatted = format ! ( " " fract ) ; if integer == 0 { // Return with the leading 0 return formatted ; } // Strip the 0 formatted = formatted [ 1 .. ] . to_string ( ) ; loop { let remainder = integer % 1000 ; integer /= 1000 ; if integer == 0 { let mut new_str = format ! ( " " remainder ) ; new_str . push_str ( & formatted ) ; formatted = new_str ; break ; } let mut new_str = format ! ( " " remainder ) ; new_str . push_str ( & formatted ) ; formatted = new_str ; } formatted }
Format f64 with US locale decimal separators
We don't care about speed or efficiency here
Assumes that f64 in this context is always smaller than u64::MAX and larger than 0
Format f64 with US locale decimal separators We don ' t care about speed or efficiency here Assumes that f64 in this context is always smaller than u64 :: MAX and larger than 0
number
f64
number
f64