Subtract the expected value from the actual value (or the other way round) and get the absolute value of the difference: ABS(A2-B2)
i32 : The 32-bit signed integer type.
Nowadays, abs
is a method on most number types.
let value = -42i32;
let x = value.abs();
The answer mentioning std::num::abs
doesn't work anymore.
Instead, use:
i32::abs(n)
fn main() {
let mut number: i32 = -8;
number = number.abs();
println!("{}", number);
}
Remember that you must specify the datatype explicitly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With