From eee2e6172a855aa0abb00219bc88ebc6b7f9b354 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Fri, 10 Apr 2020 17:21:39 +0200 Subject: [PATCH] Fix rounding of percentage calculation --- fantemp/terminal.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fantemp/terminal.hpp b/fantemp/terminal.hpp index 0a2e916..ab33938 100644 --- a/fantemp/terminal.hpp +++ b/fantemp/terminal.hpp @@ -284,7 +284,9 @@ class Terminal { const auto histogramSamples = Statistics::getHistogram(t); m_serial.template txNumber(t); m_serial << F(" C = "); - m_serial.template txNumber((histogramSamples * 100) / totalSamples); + const auto percent = + static_cast((2 * 100 * histogramSamples + totalSamples) / (2 * totalSamples)); + m_serial.template txNumber(percent); m_serial << F("%\t"); const auto normalizedSamples = static_cast(histogramSamples / normalizationFactor); for (uint8_t i = 0; i < normalizedSamples; ++i) {