Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: format_gas show two decimal places #9336

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/primitives-traits/src/constants/gas_units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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]
Expand Down
Loading