Skip to content

Commit 6e15214

Browse files
authored
fix: format_gas show two decimal places (#9336)
1 parent b3a5593 commit 6e15214

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

crates/primitives-traits/src/constants/gas_units.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ pub fn format_gas_throughput(gas: u64, execution_duration: Duration) -> String {
3535
pub fn format_gas(gas: u64) -> String {
3636
let gas = gas as f64;
3737
if gas < MEGAGAS as f64 {
38-
format!("{:.} Kgas", gas / KILOGAS as f64)
38+
format!("{:.2} Kgas", gas / KILOGAS as f64)
3939
} else if gas < GIGAGAS as f64 {
40-
format!("{:.} Mgas", gas / MEGAGAS as f64)
40+
format!("{:.2} Mgas", gas / MEGAGAS as f64)
4141
} else {
42-
format!("{:.} Ggas", gas / GIGAGAS as f64)
42+
format!("{:.2} Ggas", gas / GIGAGAS as f64)
4343
}
4444
}
4545

@@ -51,15 +51,15 @@ mod tests {
5151
fn test_gas_fmt() {
5252
let gas = 100_000;
5353
let gas_unit = format_gas(gas);
54-
assert_eq!(gas_unit, "100 Kgas");
54+
assert_eq!(gas_unit, "100.00 Kgas");
5555

5656
let gas = 100_000_000;
5757
let gas_unit = format_gas(gas);
58-
assert_eq!(gas_unit, "100 Mgas");
58+
assert_eq!(gas_unit, "100.00 Mgas");
5959

6060
let gas = 100_000_000_000;
6161
let gas_unit = format_gas(gas);
62-
assert_eq!(gas_unit, "100 Ggas");
62+
assert_eq!(gas_unit, "100.00 Ggas");
6363
}
6464

6565
#[test]

0 commit comments

Comments
 (0)