fix negative rounding

This commit is contained in:
MichaelDvP
2021-03-19 19:49:07 +01:00
committed by GitHub
parent 7885302636
commit fd11a09882

View File

@@ -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