1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-15 03:26:18 +00:00

uucore/num_format: properly display 10ᵖ where p is the precision

`seq --format %.2g 10 10` would display `1` because the precision would
not allow room for the decimal point, and the `0` in `10` would be
trimmed as an insignificant trailing `0`.

This has been fixed by only trimming trailing `0` in the presence of a
decimal point.
This commit is contained in:
Samuel Tardieu 2024-01-05 14:49:09 +01:00
parent f5179290a6
commit 32f0256d7d
2 changed files with 48 additions and 9 deletions

View file

@ -766,3 +766,23 @@ fn test_invalid_zero_increment_value() {
.no_stdout()
.usage_error("invalid Zero increment value: '0'");
}
#[test]
fn test_power_of_ten_display() {
new_ucmd!()
.args(&["-f", "%.2g", "10", "10"])
.succeeds()
.stdout_only("10\n");
}
#[test]
fn test_default_g_precision() {
new_ucmd!()
.args(&["-f", "%010g", "1e5", "1e5"])
.succeeds()
.stdout_only("0000100000\n");
new_ucmd!()
.args(&["-f", "%010g", "1e6", "1e6"])
.succeeds()
.stdout_only("000001e+06\n");
}