I'm not a python expert, but in C/C++ I'd convert and format the kWh value with the help of the printf() function into a string with two decimals (which is one line of code) before sending it as text to a text box.
By limits of the firmware, the number boxes can only hold 32bit signed integer values which are stored as 4 bytes. The rendering is done by a hex to decimal conversion.
A text box is a basically a number box with variable storage space (text length + 1byte as string terminator) which does interpret the bytes not as hex value, but as an array of ascii bytes, for rendering.
Nextion is expecting a 32 bit signed number for a Number component
Nextion does not have float support - floats with decimal will need a Text Component
Yes, since the text box is more universal (and uses a few more internal system resources).
The number boxes are to be considered as a special case, kind of "text box light" which can ONLY display 32bit signed integer values and therefore will use a little less memory. That's all.
As Nextion is a simple integer based MCU
Another means of approaching this is
Integer portion as Number Component with lenth 0
Decimal point as a Text Component or embedded in background
Fractional portion as Number component with lenth 3
For 12.098... kWh a little math PI side send 12 to first Number Component
Subtract 12 leaving you with 0.098. Multiply by 1000 - send 98 to second Number Component
Together it displays as 12.098 - Nextion side you have whole kWh and 1/1000ths kWh
I guess that two distinct number boxes would "eat up" more resources than one text box...
True, but are you really running out of resources at the moment?
One might also argue that MCU can still hold entire float
while displaying a rounded or mere integer value of kWh
My philosophy is always to well organize and optimize resource consumption from the beginning and not only when I risk to run out of resources because then, reworking things will be more time consuming.