mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-09 17:29:50 +03:00
fixed negative floats - https://github.com/proddy/EMS-ESP/issues/252
This commit is contained in:
@@ -51,22 +51,22 @@ char * _short_to_char(char * s, int16_t value, uint8_t decimals) {
|
|||||||
return (s);
|
return (s);
|
||||||
}
|
}
|
||||||
|
|
||||||
// do floating point
|
|
||||||
char s2[10] = {0};
|
|
||||||
// check for negative values
|
// check for negative values
|
||||||
if (value < 0) {
|
if (value < 0) {
|
||||||
strlcpy(s, "-", 10);
|
strlcpy(s, "-", 10);
|
||||||
value *= -1; // convert to positive
|
value *= -1; // convert to positive
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// do floating point
|
||||||
|
char s2[10] = {0};
|
||||||
if (decimals == 2) {
|
if (decimals == 2) {
|
||||||
// divide by 2
|
// divide by 2
|
||||||
strlcpy(s, ltoa(value / 2, s2, 10), 10);
|
strlcat(s, ltoa(value / 2, s2, 10), 10);
|
||||||
strlcat(s, ".", 10);
|
strlcat(s, ".", 10);
|
||||||
strlcat(s, ((value & 0x01) ? "5" : "0"), 10);
|
strlcat(s, ((value & 0x01) ? "5" : "0"), 10);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
strlcpy(s, ltoa(value / (decimals * 10), s2, 10), 10);
|
strlcat(s, ltoa(value / (decimals * 10), s2, 10), 10);
|
||||||
strlcat(s, ".", 10);
|
strlcat(s, ".", 10);
|
||||||
strlcat(s, ltoa(value % (decimals * 10), s2, 10), 10);
|
strlcat(s, ltoa(value % (decimals * 10), s2, 10), 10);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user