From ec77c572b9bf6c672c630cf3db6fff1381b0094f Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Fri, 30 Oct 2020 12:40:28 -0500 Subject: [PATCH] handle precision a tiny bit better than just hard coding to 4 decimal places. (#2712) --- crates/nu-protocol/src/value/primitive.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/nu-protocol/src/value/primitive.rs b/crates/nu-protocol/src/value/primitive.rs index 607319e669..3c45a47ceb 100644 --- a/crates/nu-protocol/src/value/primitive.rs +++ b/crates/nu-protocol/src/value/primitive.rs @@ -249,7 +249,16 @@ pub fn format_primitive(primitive: &Primitive, field_name: Option<&String>) -> S } Primitive::Duration(duration) => format_duration(duration), Primitive::Int(i) => i.to_string(), - Primitive::Decimal(decimal) => format!("{:.4}", decimal), + Primitive::Decimal(decimal) => { + // TODO: We should really pass the precision in here instead of hard coding it + let decimal_string = decimal.to_string(); + let decimal_places: Vec<&str> = decimal_string.split('.').collect(); + if decimal_places.len() == 2 && decimal_places[1].len() > 4 { + format!("{:.4}", decimal) + } else { + format!("{}", decimal) + } + } Primitive::Range(range) => format!( "{}..{}{}", format_primitive(&range.from.0.item, None),