mirror of
https://github.com/nushell/nushell
synced 2024-12-28 22:13:10 +00:00
Force floats to output a decimal in nuon (#5768)
* Force floats to output a decimal in nuon * Add test
This commit is contained in:
parent
9dbf7556b8
commit
7ae7394c85
2 changed files with 19 additions and 1 deletions
|
@ -86,7 +86,13 @@ fn value_to_string(v: &Value, span: Span) -> Result<String, ShellError> {
|
||||||
span,
|
span,
|
||||||
)),
|
)),
|
||||||
Value::Filesize { val, .. } => Ok(format!("{}b", *val)),
|
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::Int { val, .. } => Ok(format!("{}", *val)),
|
||||||
Value::List { vals, .. } => {
|
Value::List { vals, .. } => {
|
||||||
let headers = get_columns(vals);
|
let headers = get_columns(vals);
|
||||||
|
|
|
@ -190,3 +190,15 @@ fn read_bool() {
|
||||||
|
|
||||||
assert_eq!(actual.out, "true")
|
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")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue