From fd11a0988276cf729e77c0d09534425fd9766765 Mon Sep 17 00:00:00 2001 From: MichaelDvP <59284019+MichaelDvP@users.noreply.github.com> Date: Fri, 19 Mar 2021 19:49:07 +0100 Subject: [PATCH] fix negative rounding --- src/helpers.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/helpers.cpp b/src/helpers.cpp index a86cef399..4eaac6eb5 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -358,7 +358,11 @@ uint16_t Helpers::atoint(const char * value) { // rounds a number to 2 decimal places // example: round2(3.14159) -> 3.14 double Helpers::round2(double value, const uint8_t divider) { - return (int)((value / divider) * 100 + 0.5) / 100.0; + if (value >= 0) { + return (int)(value * 100 + 0.5) / 100.0; + } else { + return (int)(value * 100 - 0.5) / 100.0; + } } // abs of a signed 32-bit integer