Skip to content
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.

Commit

Permalink
fix negative rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP authored Mar 19, 2021
1 parent 220fed8 commit a59df64
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,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) {
return (int)(value * 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;
}
}

bool Helpers::check_abs(const int32_t i) {
Expand Down

0 comments on commit a59df64

Please sign in to comment.