MCPcopy Create free account
hub / github.com/NotAShelf/microfetch / write_float

Function write_float

crates/lib/src/system.rs:106–123  ·  view source on GitHub ↗
(s: &mut String, val: f64, decimals: u32)

Source from the content-addressed store, hash-verified

104 clippy::cast_precision_loss
105)]
106fn write_float(s: &mut String, val: f64, decimals: u32) {
107 // Handle integer part
108 let int_part = val as u64;
109 write_u64(s, int_part);
110
111 if decimals > 0 {
112 s.push('.');
113
114 // Calculate fractional part
115 let mut frac = val - int_part as f64;
116 for _ in 0..decimals {
117 frac *= 10.0;
118 let digit = frac as u8;
119 s.push((b'0' + digit) as char);
120 frac -= f64::from(digit);
121 }
122 }
123}
124
125/// Round an f64 to nearest integer (`f64::round` is not in core)
126#[allow(

Callers 2

get_root_disk_usageFunction · 0.85
get_memory_usageFunction · 0.85

Calls 1

write_u64Function · 0.85

Tested by

no test coverage detected