diff options
author | Vincent Ambo <mail@tazj.in> | 2022-08-10T17·01+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-08-25T10·41+0000 |
commit | 522d93745c3b92a93493c2d81c01e3cf6267994e (patch) | |
tree | 1c6ef269cc2bd02692e1269a2bd3de7283dd6bb6 /tvix/eval/src/value/mod.rs | |
parent | ad1c11b60677c020c1e62601b63bfb0d8e49234f (diff) |
fix(tvix/value): fix display representation of floats r/4469
Nix displays a maximum of 5 digits for floating points. Change-Id: Ifa3c0d96fa0b24e3be8f94dfebc99e602a258355 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6133 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/value/mod.rs')
-rw-r--r-- | tvix/eval/src/value/mod.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/tvix/eval/src/value/mod.rs b/tvix/eval/src/value/mod.rs index 99c7ee8647c3..0a430ae08cb3 100644 --- a/tvix/eval/src/value/mod.rs +++ b/tvix/eval/src/value/mod.rs @@ -80,11 +80,17 @@ impl Display for Value { Value::Bool(true) => f.write_str("true"), Value::Bool(false) => f.write_str("false"), Value::Integer(num) => f.write_fmt(format_args!("{}", num)), - Value::Float(num) => f.write_fmt(format_args!("{}", num)), Value::String(s) => s.fmt(f), Value::Attrs(attrs) => attrs.fmt(f), Value::List(list) => list.fmt(f), + // Nix prints floats with a maximum precision of 5 digits + // only. + Value::Float(num) => f.write_fmt(format_args!( + "{}", + format!("{:.5}", num).trim_end_matches(['.', '0']) + )), + // internal types Value::AttrPath(_) | Value::Blackhole => f.write_str("internal"), } |