fn fmt_decimal(
            f: &mut fmt::Formatter,
            mut integer_part: u64,
            mut fractional_part: u32,
            mut divisor: u32,
        ) -> fmt::Result {
            // Encode the fractional part into a temporary buffer. The buffer
            // only need to hold 9 elements, because `fractional_part` has to
            // be smaller than 10^9. The buffer is prefilled with '0' digits
            // to simplify the code below.
            let mut buf = [b'0'; 9];

            // The next digit is written at this position
            let mut pos = 0;

            // We keep writing digits into the buffer while there are non-zero
            // digits left and we haven't written enough digits yet.
            while fractional_part > 0 && pos < f.precision().unwrap_or(9) {
                // Write new digit into the buffer
                buf[pos] = b'0' + (fractional_part / divisor) as u8;

                fractional_part %= divisor;
                divisor /= 10;
                pos += 1;
            }

            // If a precision < 9 was specified, there may be some non-zero
            // digits left that weren't written into the buffer. In that case we
            // need to perform rounding to match the semantics of printing
            // normal floating point numbers. However, we only need to do work
            // when rounding up. This happens if the first digit of the
            // remaining ones is >= 5.
            if fractional_part > 0 && fractional_part >= divisor * 5 {
                // Round up the number contained in the buffer. We go through
                // the buffer backwards and keep track of the carry.
                let mut rev_pos = pos;
                let mut carry = true;
                while carry && rev_pos > 0 {
                    rev_pos -= 1;

                    // If the digit in the buffer is not '9', we just need to
                    // increment it and can stop then (since we don't have a
                    // carry anymore). Otherwise, we set it to '0' (overflow)
                    // and continue.
                    if buf[rev_pos] < b'9' {
                        buf[rev_pos] += 1;
                        carry = false;
                    } else {
                        buf[rev_pos] = b'0';
                    }
                }

                // If we still have the carry bit set, that means that we set
                // the whole buffer to '0's and need to increment the integer
                // part.
                if carry {
                    integer_part += 1;
                }
            }

            // Determine the end of the buffer: if precision is set, we just
            // use as many digits from the buffer (capped to 9). If it isn't
            // set, we only use all digits up to the last non-zero one.
            let end = f.precision().map(|p| ::cmp::min(p, 9)).unwrap_or(pos);

            // If we haven't emitted a single fractional digit and the precision
            // wasn't set to a non-zero value, we don't print the decimal point.
            if end == 0 {
                write!(f, "{}", integer_part)
            } else {
                // We are only writing ASCII digits into the buffer and it was
                // initialized with '0's, so it contains valid UTF8.
                let s = unsafe {
                    ::str::from_utf8_unchecked(&buf[..end])
                };

                // If the user request a precision > 9, we pad '0's at the end.
                let w = f.precision().unwrap_or(pos);
                write!(f, "{}.{:0<width$}", integer_part, s, width = w)
            }
        }
/// 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`!
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`.


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 ` .
fn fmt_decimal(
            f: &mut fmt::Formatter,
            mut integer_part: u64,
            mut fractional_part: u32,
            mut divisor: u32,
        ) -> fmt::Result {
            // Encode the fractional part into a temporary buffer. The buffer
            // only need to hold 9 elements, because `fractional_part` has to
            // be smaller than 10^9. The buffer is prefilled with '0' digits
            // to simplify the code below.
            let mut buf = [b'0'; 9];
            // The next digit is written at this position
            let mut pos = 0;
            // We keep writing digits into the buffer while there are non-zero
            // digits left and we haven't written enough digits yet.
            while fractional_part > 0 && pos < f.precision().unwrap_or(9) {
                // Write new digit into the buffer
                buf[pos] = b'0' + (fractional_part / divisor) as u8;
                fractional_part %= divisor;
                divisor /= 10;
                pos += 1;
            }
            // If a precision < 9 was specified, there may be some non-zero
            // digits left that weren't written into the buffer. In that case we
            // need to perform rounding to match the semantics of printing
            // normal floating point numbers. However, we only need to do work
            // when rounding up. This happens if the first digit of the
            // remaining ones is >= 5.
            if fractional_part > 0 && fractional_part >= divisor * 5 {
                // Round up the number contained in the buffer. We go through
                // the buffer backwards and keep track of the carry.
                let mut rev_pos = pos;
                let mut carry = true;
                while carry && rev_pos > 0 {
                    rev_pos -= 1;
                    // If the digit in the buffer is not '9', we just need to
                    // increment it and can stop then (since we don't have a
                    // carry anymore). Otherwise, we set it to '0' (overflow)
                    // and continue.
                    if buf[rev_pos] < b'9' {
                        buf[rev_pos] += 1;
                        carry = false;
                    } else {
                        buf[rev_pos] = b'0';
                    }
                }
                // If we still have the carry bit set, that means that we set
                // the whole buffer to '0's and need to increment the integer
                // part.
                if carry {
                    integer_part += 1;
                }
            }
            // Determine the end of the buffer: if precision is set, we just
            // use as many digits from the buffer (capped to 9). If it isn't
            // set, we only use all digits up to the last non-zero one.
            let end = f.precision().map(|p| ::cmp::min(p, 9)).unwrap_or(pos);
            // If we haven't emitted a single fractional digit and the precision
            // wasn't set to a non-zero value, we don't print the decimal point.
            if end == 0 {
                write!(f, "{}", integer_part)
            } else {
                // We are only writing ASCII digits into the buffer and it was
                // initialized with '0's, so it contains valid UTF8.
                let s = unsafe {
                    ::str::from_utf8_unchecked(&buf[..end])
                };
                // If the user request a precision > 9, we pad '0's at the end.
                let w = f.precision().unwrap_or(pos);
                write!(f, "{}.{:0<width$}", integer_part, s, width = w)
            }
        }
fn fmt_decimal ( f : & mut fmt :: Formatter , mut integer_part : u64 , mut fractional_part : u32 , mut divisor : u32 , ) -> fmt :: Result { // Encode the fractional part into a temporary buffer. The buffer // only need to hold 9 elements, because `fractional_part` has to // be smaller than 10^9. The buffer is prefilled with '0' digits // to simplify the code below. let mut buf = [ b'0' ; 9 ] ; // The next digit is written at this position let mut pos = 0 ; // We keep writing digits into the buffer while there are non-zero // digits left and we haven't written enough digits yet. while fractional_part > 0 && pos < f . precision ( ) . unwrap_or ( 9 ) { // Write new digit into the buffer buf [ pos ] = b'0' + ( fractional_part / divisor ) as u8 ; fractional_part %= divisor ; divisor /= 10 ; pos += 1 ; } // If a precision < 9 was specified, there may be some non-zero // digits left that weren't written into the buffer. In that case we // need to perform rounding to match the semantics of printing // normal floating point numbers. However, we only need to do work // when rounding up. This happens if the first digit of the // remaining ones is >= 5. if fractional_part > 0 && fractional_part >= divisor * 5 { // Round up the number contained in the buffer. We go through // the buffer backwards and keep track of the carry. let mut rev_pos = pos ; let mut carry = true ; while carry && rev_pos > 0 { rev_pos -= 1 ; // If the digit in the buffer is not '9', we just need to // increment it and can stop then (since we don't have a // carry anymore). Otherwise, we set it to '0' (overflow) // and continue. if buf [ rev_pos ] < b'9' { buf [ rev_pos ] += 1 ; carry = false ; } else { buf [ rev_pos ] = b'0' ; } } // If we still have the carry bit set, that means that we set // the whole buffer to '0's and need to increment the integer // part. if carry { integer_part += 1 ; } } // Determine the end of the buffer: if precision is set, we just // use as many digits from the buffer (capped to 9). If it isn't // set, we only use all digits up to the last non-zero one. let end = f . precision ( ) . map ( | p | :: cmp :: min ( p , 9 ) ) . unwrap_or ( pos ) ; // If we haven't emitted a single fractional digit and the precision // wasn't set to a non-zero value, we don't print the decimal point. if end == 0 { write ! ( f " " integer_part ) } else { // We are only writing ASCII digits into the buffer and it was // initialized with '0's, so it contains valid UTF8. let s = unsafe { :: str :: from_utf8_unchecked ( & buf [ .. end ] ) } ; // If the user request a precision > 9, we pad '0's at the end. let w = f . precision ( ) . unwrap_or ( pos ) ; write ! ( f " " integer_part s width w ) } }
Formats a floating point number in decimal notation.
Formats a floating point number in decimal notation .
f
&mut fmt::Formatter
integer_part
u64
fractional_part
u32
divisor
u32
f
&mut fmt::Formatter
integer_part
u64
fractional_part
u32
divisor
u32