Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 8 additions & 2 deletions src/uu/numfmt/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,12 @@ fn transform_from(s: &str, opts: &TransformOptions, options: &NumfmtOptions) ->
.map_err(|original| {
detailed_error_message(s, opts.from, &options.unit_separator).unwrap_or(original)
})?;
let had_no_suffix = suffix.is_none();
let i = i * (opts.from_unit as f64);

remove_suffix(i, suffix, opts.from).map(|n| {
// GNU numfmt doesn't round values if no --from argument is provided by the user
if opts.from == Unit::None {
if opts.from == Unit::None || had_no_suffix {
if n == -0.0 { 0.0 } else { n }
} else if n < 0.0 {
-n.abs().ceil()
Expand Down Expand Up @@ -541,7 +542,12 @@ fn format_string(

let precision = if let Some(p) = options.format.precision {
p
} else if options.transform.from == Unit::None && options.transform.to == Unit::None {
} else if options.transform.to == Unit::None
&& !source_without_suffix
.chars()
.last()
.is_some_and(char::is_alphabetic)
{
parse_implicit_precision(source_without_suffix)
} else {
0
Expand Down
1 change: 0 additions & 1 deletion tests/by-util/test_numfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,6 @@ fn test_to_auto_rejected_at_parse_time_issue_11662() {
// `--from-unit` multiplication with fractional input rounds to an integer;
// GNU preserves the fractional digits.
#[test]
#[ignore = "GNU compat: see uutils/coreutils#11663"]
fn test_from_unit_fractional_precision_issue_11663() {
new_ucmd!()
.args(&["--from=iec", "--from-unit=959", "--", "-615484.454"])
Expand Down
Loading