bottest/tests/unit/basic/basic_keywords_math_round.rs

28 lines
524 B
Rust
Raw Normal View History

2025-12-23 18:41:29 -03:00
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(dead_code)]
#[test]
2025-12-23 18:41:29 -03:00
fn test_round_basic() {
assert_eq!(3.7_f64.round() as i64, 4);
assert_eq!(3.2_f64.round() as i64, 3);
assert_eq!((-3.7_f64).round() as i64, -4);
}
#[test]
2025-12-23 18:41:29 -03:00
fn test_round_decimals() {
let n = 2.71828_f64;
let decimals = 2;
let factor = 10_f64.powi(decimals);
let result = (n * factor).round() / factor;
assert!((result - 2.72).abs() < 0.001);
}