Merge pull request #718 from MichaelDvP/dev

fix #717, rounding error
This commit is contained in:
Proddy
2022-11-01 18:09:31 +01:00
committed by GitHub

View File

@@ -297,7 +297,7 @@ char * Helpers::render_value(char * result, const int32_t value, const int8_t fo
} else if (format > 0) {
strlcat(result, itoa(new_value / format, s, 10), sizeof(s));
strlcat(result, ".", sizeof(s));
strlcat(result, itoa((new_value % format + format / 2) * 10 / format, s, 10), sizeof(s));
strlcat(result, itoa(((new_value % format) * 10 + format / 2) / format, s, 10), sizeof(s));
} else {
strlcat(result, itoa(new_value * format * -1, s, 10), sizeof(s));
}
@@ -337,9 +337,9 @@ char * Helpers::render_value(char * result, const uint32_t value, const int8_t f
if (!hasValue(value)) {
return nullptr;
}
result[0] = '\0';
int32_t new_value = fahrenheit ? format ? value * 1.8 + 32 * format * (fahrenheit - 1) : value * 1.8 + 32 * (fahrenheit - 1) : value;
char s[10] = {0};
result[0] = '\0';
uint32_t new_value = fahrenheit ? format ? value * 1.8 + 32 * format * (fahrenheit - 1) : value * 1.8 + 32 * (fahrenheit - 1) : value;
char s[10] = {0};
#ifndef EMSESP_STANDALONE
if (!format) {
@@ -347,7 +347,7 @@ char * Helpers::render_value(char * result, const uint32_t value, const int8_t f
} else if (format > 0) {
strlcpy(result, ltoa(new_value / format, s, 10), sizeof(s));
strlcat(result, ".", sizeof(s));
strlcat(result, itoa((new_value % format + format / 2) * 10 / format, s, 10), sizeof(s));
strlcat(result, itoa(((new_value % format) * 10 + format / 2) / format, s, 10), sizeof(s));
} else {
strlcpy(result, ltoa(new_value * format * -1, s, 10), sizeof(s));
}