Rust 中四舍五入算法
fn round(nr: f32, places:usize) -> f32 { let multiplier = 10_f32.powi(places as i32); (nr * multiplier + 0.5).floor() / multiplier } fn main() { println!("{}", round(3.1456, 2)); }
暂无评论
添加评论,请登录
呼吸智能 ©HuXi.Fun