Start a new topic
Solved

Parenthesis and Decimal numbers in equations.

I have been trying to get some equations to work, using regular normal expressions.


fuelG.pic=46 - ((20/100)*fuel_var.val)


This should change the image displayed in the fuelG image box to the correct image in a 20 image sequence. fuel_var holds a number that was passed to it from the main MCU between 0 and 100...


The maths is sound and is a normal style of expression. But the IDE wont compile it.


Removing parenthesis obviously brakes the formula and would result is incorrect numbers being calculated.


Also you will notice 20/100 is 0.2

This is another issue the ide doesnt like handling decimals. In most normal situations a decimal would be rounded to the nearest whole number. But the compiler throws another error.



1 Comment

Nextion Instruction Set states - complex expressions not supported

Order of operations requires complex expressions


Nextion is integer based without floating point

   30/100 is 0  

   250/100 is 2

   99 /25 is 3


Parsing is occurring on each operator right to left.


fuelG.pic=46-20/100*fuel_var.val

will parse as

  fuelG.pic=46-20

  fuelG.pic=fuelG.pic/100

  fuelG.pic=fuelG.pic*fuel_var.val


The proper way to approach such is

va0.val=46

va1.val=20*fuel_val.val/100

fuelG.pic=va0.val-va1.val


This is not a Bug but the expected behaviour on embedded integer based level

Login or Signup to post a comment