Add --to-float to str plugin (#1872)

This commit is contained in:
k-brk
2020-05-25 00:11:49 +02:00
committed by GitHub
parent fb09d7d1a1
commit 8a99d112fc
9 changed files with 86 additions and 5 deletions

View File

@ -179,7 +179,16 @@ pub fn autoview(context: RunnableContext) -> Result<OutputStream, ShellError> {
value: UntaggedValue::Primitive(Primitive::Decimal(n)),
..
} => {
out!("{}", n);
// TODO: normalize decimal to remove trailing zeros.
// normalization will be available in next release of bigdecimal crate
let mut output = n.to_string();
if output.contains('.') {
output = output.trim_end_matches('0').to_owned();
}
if output.ends_with('.') {
output.push('0');
}
out!("{}", output);
}
Value {
value: UntaggedValue::Primitive(Primitive::Boolean(b)),