fix: rendering of floats

This commit is contained in:
proddy
2021-03-21 13:14:05 +01:00
parent 8ec0731ca2
commit 4db69760c6

View File

@@ -358,11 +358,13 @@ uint16_t Helpers::atoint(const char * value) {
// rounds a number to 2 decimal places // rounds a number to 2 decimal places
// example: round2(3.14159) -> 3.14 // example: round2(3.14159) -> 3.14
double Helpers::round2(double value, const uint8_t divider) { double Helpers::round2(double value, const uint8_t divider) {
uint8_t div = (divider ? divider : 1); // prevent div-by-zero
if (value >= 0) { if (value >= 0) {
return (int)(value * 100 + 0.5) / 100.0; return (int)((value / div) * 100 + 0.5) / 100.0;
} else {
return (int)(value * 100 - 0.5) / 100.0;
} }
return (int)((value / div) * 100 - 0.5) / 100.0; // negative values
} }
// abs of a signed 32-bit integer // abs of a signed 32-bit integer