From a871f2344a048c943dfdf3ae3fceeca52a042678 Mon Sep 17 00:00:00 2001 From: pwygab <88221256+merelymyself@users.noreply.github.com> Date: Sat, 6 Aug 2022 20:10:33 +0800 Subject: [PATCH] fix examples and let into decimal convert bools too (#6246) --- .../nu-command/src/conversions/into/decimal.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/crates/nu-command/src/conversions/into/decimal.rs b/crates/nu-command/src/conversions/into/decimal.rs index 5e42d1cfaf..c62821d135 100644 --- a/crates/nu-command/src/conversions/into/decimal.rs +++ b/crates/nu-command/src/conversions/into/decimal.rs @@ -42,7 +42,7 @@ impl Command for SubCommand { fn examples(&self) -> Vec { vec![ Example { - description: "Convert string to integer in table", + description: "Convert string to decimal in table", example: "[[num]; ['5.01']] | into decimal num", result: Some(Value::List { vals: vec![Value::Record { @@ -54,15 +54,20 @@ impl Command for SubCommand { }), }, Example { - description: "Convert string to integer", + description: "Convert string to decimal", example: "'1.345' | into decimal", result: Some(Value::test_float(1.345)), }, Example { - description: "Convert decimal to integer", + description: "Convert decimal to decimal", example: "'-5.9' | into decimal", result: Some(Value::test_float(-5.9)), }, + Example { + description: "Convert boolean to decimal", + example: "true | into decimal", + result: Some(Value::test_float(1.0)), + }, ] } } @@ -118,6 +123,13 @@ fn action(input: &Value, head: Span) -> Value { val: *v as f64, span: *span, }, + Value::Bool { val: b, span } => Value::Float { + val: match b { + true => 1.0, + false => 0.0, + }, + span: *span, + }, other => { let span = other.span(); match span {