mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-10 11:45:39 +00:00
test - better rounding|?
This commit is contained in:
@ -436,7 +436,27 @@ HassDeviceInfo* hass_init_power_sensor_device_info(int index) {
|
||||
|
||||
// generate string like "{{ float(value)*0.1|round(2) }}"
|
||||
// {{ float(value)*0.1 }} for value=12 give 1.2000000000000002, using round() to limit the decimal places
|
||||
// 2023 10 19 - it is not a perfect solution, it's better to use:
|
||||
// {{ '%0.2f'|format(states('sensor.varasto2_osram_temp')|float + 0.7) }}
|
||||
//
|
||||
char *hass_generate_multiplyAndRound_template(int decimalPlacesForRounding, int decimalPointOffset, int divider) {
|
||||
#if 1
|
||||
char tmp[8];
|
||||
int i;
|
||||
|
||||
strcpy(g_hassBuffer, "{{ '%0.");
|
||||
sprintf(tmp, "%if", decimalPlacesForRounding);
|
||||
strcat(g_hassBuffer, tmp);
|
||||
strcat(g_hassBuffer, "'|format(float(value)");
|
||||
if (decimalPointOffset != 0) {
|
||||
strcat(g_hassBuffer, "*0.");
|
||||
for (i = 1; i < decimalPointOffset; i++) {
|
||||
strcat(g_hassBuffer, "0");
|
||||
}
|
||||
strcat(g_hassBuffer, "1");
|
||||
}
|
||||
strcat(g_hassBuffer, ") }}");
|
||||
#else
|
||||
char tmp[8];
|
||||
int i;
|
||||
|
||||
@ -454,7 +474,7 @@ char *hass_generate_multiplyAndRound_template(int decimalPlacesForRounding, int
|
||||
sprintf(tmp, "%i", decimalPlacesForRounding);
|
||||
strcat(g_hassBuffer, tmp);
|
||||
strcat(g_hassBuffer, ") }}");
|
||||
|
||||
#endif
|
||||
return g_hassBuffer;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user