From 6e1521456623aa3dbec586e3aa48b642c1fe28d5 Mon Sep 17 00:00:00 2001 From: Park Smith <161195644+sdfii@users.noreply.github.com> Date: Sat, 6 Jul 2024 04:58:49 +0100 Subject: [PATCH] fix: format_gas show two decimal places (#9336) --- crates/primitives-traits/src/constants/gas_units.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/primitives-traits/src/constants/gas_units.rs b/crates/primitives-traits/src/constants/gas_units.rs index 11caab5139..0af0d2c24c 100644 --- a/crates/primitives-traits/src/constants/gas_units.rs +++ b/crates/primitives-traits/src/constants/gas_units.rs @@ -35,11 +35,11 @@ pub fn format_gas_throughput(gas: u64, execution_duration: Duration) -> String { pub fn format_gas(gas: u64) -> String { let gas = gas as f64; if gas < MEGAGAS as f64 { - format!("{:.} Kgas", gas / KILOGAS as f64) + format!("{:.2} Kgas", gas / KILOGAS as f64) } else if gas < GIGAGAS as f64 { - format!("{:.} Mgas", gas / MEGAGAS as f64) + format!("{:.2} Mgas", gas / MEGAGAS as f64) } else { - format!("{:.} Ggas", gas / GIGAGAS as f64) + format!("{:.2} Ggas", gas / GIGAGAS as f64) } } @@ -51,15 +51,15 @@ mod tests { fn test_gas_fmt() { let gas = 100_000; let gas_unit = format_gas(gas); - assert_eq!(gas_unit, "100 Kgas"); + assert_eq!(gas_unit, "100.00 Kgas"); let gas = 100_000_000; let gas_unit = format_gas(gas); - assert_eq!(gas_unit, "100 Mgas"); + assert_eq!(gas_unit, "100.00 Mgas"); let gas = 100_000_000_000; let gas_unit = format_gas(gas); - assert_eq!(gas_unit, "100 Ggas"); + assert_eq!(gas_unit, "100.00 Ggas"); } #[test]