handle precision a tiny bit better than just hard coding to 4 decimal places. (#2712)

This commit is contained in:
Darren Schroeder 2020-10-30 12:40:28 -05:00 committed by GitHub
parent f97561c416
commit ec77c572b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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),