From 7c6b44461625bc25298ead7ab5a9c378772a343c Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Wed, 3 Nov 2021 08:44:07 +0800 Subject: [PATCH] Fix display of 0.0. --- CHANGELOG.md | 9 +++++++++ src/ast.rs | 4 +++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7de172a..ad096ea5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ Rhai Release Notes ================== +Version 1.1.2 +============= + +Bug fixes +--------- + +* `0.0` now prints correctly (used to print `0e0`). + + Version 1.1.1 ============= diff --git a/src/ast.rs b/src/ast.rs index 34d492a5..a344607b 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1825,7 +1825,9 @@ impl fmt::Debug for FloatWrapper { impl> fmt::Display for FloatWrapper { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let abs = self.0.abs(); - if abs > Self::MAX_NATURAL_FLOAT_FOR_DISPLAY.into() + if abs.fract().is_zero() { + f.write_str("0.0") + } else if abs > Self::MAX_NATURAL_FLOAT_FOR_DISPLAY.into() || abs < Self::MIN_NATURAL_FLOAT_FOR_DISPLAY.into() { write!(f, "{:e}", self.0)