openshwprojects / OpenBK7231T_App

Open source firmware (Tasmota/Esphome replacement) for BK7231T, BK7231N, BL2028N, T34, XR809, W800/W801, W600/W601, BL602 and LN882H
https://openbekeniot.github.io/webapp/devicesList.html
1.41k stars 245 forks source link

We need better rounding for sprintf #585

Open openshwprojects opened 1 year ago

openshwprojects commented 1 year ago

Our lightweight sprintf replacement needs better rounding.

I got such report:

The 2 decimal points seems to be working except for the energy. It rounded 0.8299999... to 0.82 but the value should be 0.83. Seems to truncate and not round.

The syntax used for rounding is:

    poststr(request, "<tr><td>");
            hprintf255(request, "Temperature Channel %i value %.2f C<br>", i, fValue);
            poststr(request, "</td></tr>");

can anyone look into that or should I investigate it myself? @iprak @btsimonh @valeklubomir

iprak commented 1 year ago

Is the actual printing now happening via nanoprintf ?

openshwprojects commented 1 year ago

Yes in nanoprintf.

So either fix nanoprintf or createt a dedicated other hacky function for proper rounding.

I'd prefer nanoprintf fix

iprak commented 1 year ago

This seems to be the current implementation in nanoprintf (in readme). There are multiple issues logged in that project for enhancing the floating/precision aspect.