foundry_common_fmt::exp

Function format_uint_exp

Source
pub fn format_uint_exp(num: U256) -> String
Expand description

Formats a U256 number to string, adding an exponential notation hint if it is larger than 10_000, with a precision of 4 figures, and trimming the trailing zeros.

ยงExamples

use alloy_primitives::U256;
use foundry_common_fmt::format_uint_exp as f;

assert_eq!(f(U256::from(0)), "0");
assert_eq!(f(U256::from(1234)), "1234");
assert_eq!(f(U256::from(1234567890)), "1234567890 [1.234e9]");
assert_eq!(f(U256::from(1000000000000000000_u128)), "1000000000000000000 [1e18]");
assert_eq!(f(U256::from(10000000000000000000000_u128)), "10000000000000000000000 [1e22]");