MCPcopy Index your code
hub / github.com/RustPython/RustPython / format_fixed

Function format_fixed

crates/literal/src/float.rs:57–68  ·  view source on GitHub ↗
(precision: usize, magnitude: f64, case: Case, alternate_form: bool)

Source from the content-addressed store, hash-verified

55}
56
57pub fn format_fixed(precision: usize, magnitude: f64, case: Case, alternate_form: bool) -> String {
58 match magnitude {
59 magnitude if magnitude.is_finite() => {
60 let point = decimal_point_or_empty(precision, alternate_form);
61 let precision = core::cmp::min(precision, u16::MAX as usize);
62 format!("{magnitude:.precision$}{point}")
63 }
64 magnitude if magnitude.is_nan() => format_nan(case),
65 magnitude if magnitude.is_infinite() => format_inf(case),
66 _ => "".to_string(),
67 }
68}
69
70// Formats floats into Python style exponent notation, by first formatting in Rust style
71// exponent notation (`1.0000e0`), then convert to Python style (`1.0000e+00`).

Callers 3

format_floatMethod · 0.85
format_complex_floatMethod · 0.85
format_floatMethod · 0.85

Calls 8

decimal_point_or_emptyFunction · 0.85
minFunction · 0.85
format_nanFunction · 0.85
format_infFunction · 0.85
to_stringMethod · 0.80
is_finiteMethod · 0.45
is_nanMethod · 0.45
is_infiniteMethod · 0.45

Tested by

no test coverage detected