I am trying to figure out how to do math (division in my case), and display that answer as a decimal in a text box. I thought I could be sneaky and convert a number value (int) into a text box (string), but I have already lost the decimal values at that point. The code I tried was:
I have a value that I set with a slider. I then want to take 4000 divided by that value, and display it as a decimal number, not an integer. My slider will go from 1 to 2047.
Is there anyway to do this within the Nextion editor. I'm know I can send the value out to an arduino, have it do the math and send back a decimal string, but I don't want to do that if Nextion can do it.
I haven't seen any float capabilities. division provides whole number division on STM32F.
Not to be a replacement for float, but you could multiply 4000*factor before division, then incrementally calc
then move your decimal point over three. I haven't seen string manipulation either.
[SOLVED] "sort of"
In the above posts Patrick had a great idea to get around the lack of float math operations by using large integer values to capture the decimal places, then just shift the decimal point accordingly. Unfortunately, the Nextion Editor also lacks, as far as I can tell, any string manipulation commands. So In order for this to work, it would all have to be done by hand.
The way I solved this issue was as follows:
va0.val=4000/h0.val <<capture value before decimal
va1.val=40000000/h0.val <<capture 4 decimal values (add more zeros for more decimals
va2.val=va0.val*10000 <<multiply original value by multiplier in line 2 to isolate decimal
va3.val=va1.val-va2.val <<determine the decimal value
cov va0.val,va4.txt,0 <<save value before decimal as text
cov va3.val,va5.txt,4 <<save decimal as text
t0.txt=va4.txt+"."+va5.txt <<display whole value as text
This seems to work well for me. It certainly isn't clean, but it gets the job done. I would leave to here any other ideas on how to accomplish this. Hope this helps somebody!