Fix rounding of percentage calculation

This commit is contained in:
BlackMark 2020-04-10 17:21:39 +02:00
parent d6269952a6
commit eee2e6172a

View File

@ -284,7 +284,9 @@ class Terminal {
const auto histogramSamples = Statistics::getHistogram(t);
m_serial.template txNumber<uint8_t, 10, 2>(t);
m_serial << F(" C = ");
m_serial.template txNumber<uint8_t, 10, 3, ' '>((histogramSamples * 100) / totalSamples);
const auto percent =
static_cast<uint8_t>((2 * 100 * histogramSamples + totalSamples) / (2 * totalSamples));
m_serial.template txNumber<uint8_t, 10, 3, ' '>(percent);
m_serial << F("%\t");
const auto normalizedSamples = static_cast<uint8_t>(histogramSamples / normalizationFactor);
for (uint8_t i = 0; i < normalizedSamples; ++i) {