mirror of
https://github.com/nushell/nushell.git
synced 2025-03-31 19:27:09 +02:00
handle precision a tiny bit better than just hard coding to 4 decimal places. (#2712)
This commit is contained in:
parent
f97561c416
commit
ec77c572b9
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user