diff --git a/crates/nu-command/src/formats/to/nuon.rs b/crates/nu-command/src/formats/to/nuon.rs index 750d506cb1..aae3007b93 100644 --- a/crates/nu-command/src/formats/to/nuon.rs +++ b/crates/nu-command/src/formats/to/nuon.rs @@ -86,7 +86,13 @@ fn value_to_string(v: &Value, span: Span) -> Result { span, )), Value::Filesize { val, .. } => Ok(format!("{}b", *val)), - Value::Float { val, .. } => Ok(format!("{}", *val)), + Value::Float { val, .. } => { + if &val.round() == val { + Ok(format!("{}.0", *val)) + } else { + Ok(format!("{}", *val)) + } + } Value::Int { val, .. } => Ok(format!("{}", *val)), Value::List { vals, .. } => { let headers = get_columns(vals); diff --git a/crates/nu-command/tests/format_conversions/nuon.rs b/crates/nu-command/tests/format_conversions/nuon.rs index d1fe9d23f1..7f4c0e136a 100644 --- a/crates/nu-command/tests/format_conversions/nuon.rs +++ b/crates/nu-command/tests/format_conversions/nuon.rs @@ -190,3 +190,15 @@ fn read_bool() { assert_eq!(actual.out, "true") } + +#[test] +fn float_doesnt_become_int() { + let actual = nu!( + cwd: "tests/fixtures/formats", pipeline( + r#" + 1.0 | to nuon + "# + )); + + assert_eq!(actual.out, "1.0") +}