a simple help on syntax

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
giorgino
Normal user
Posts: 126
Joined: 24 Oct 2022, 21:06

a simple help on syntax

#1 Post by giorgino » 21 Oct 2024, 21:53

an easy question...
working with floating number, I need to pass integer value to this
NEXTION,page2.n0.val=6
and I obtain 6

and when I have 2 integer:
NEXTION,page2.n0.val=6+2
obatain 8

then I write
NEXTION,page2.n0.val=7.2+2
and doesn't work

...I know, it' s so easy...

TD-er
Core team member
Posts: 9884
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: a simple help on syntax

#2 Post by TD-er » 21 Oct 2024, 22:07

I guess you're generating these in rules?

If so, then you can use the let command to compute an intermediate value and store it in a variable.

Code: Select all

let,1,7.2+2 // Store in variable #1
NEXTION,page2.n0.val=[var#1]

giorgino
Normal user
Posts: 126
Joined: 24 Oct 2022, 21:06

Re: a simple help on syntax

#3 Post by giorgino » 21 Oct 2024, 22:22

ah , ok
so, no direct in the
NEXTION,page2.n0.val=7.2+2
?

TD-er
Core team member
Posts: 9884
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: a simple help on syntax

#4 Post by TD-er » 21 Oct 2024, 22:32

The inline-parsing isn't working like that.
Only with the '=' on the first position when parsing numerical values, the parser will try to evaluate the formula.
However this may give some unexpected results, so best to use "let" to evaluate calculations.

giorgino
Normal user
Posts: 126
Joined: 24 Oct 2022, 21:06

Re: a simple help on syntax

#5 Post by giorgino » 21 Oct 2024, 23:01

ok, good!
now, I need to send integer, so my syntax become:
let,1,round(([MQTbox#dm_vol]-9000)*0.03) // Store in variable #1 l'angolo di riferimento dei volt batteria (dm_volt)
NEXTION,page1.z1.val=[var#1]
but if I need to truncate my floating 12.347 to 12.34 can I use something like ROUND(x,2) ?

User avatar
Ath
Normal user
Posts: 4330
Joined: 10 Jun 2018, 12:06
Location: NL

Re: a simple help on syntax

#6 Post by Ath » 21 Oct 2024, 23:16

You'll need a transformation, as documented here
So your case could be like

Code: Select all

let,1,([MQTbox#dm_vol]-9000)*0.03 // Store in variable #1 l'angolo di riferimento dei volt batteria (dm_volt)
NEXTION,page1.z1.val=[var#1#d1.2]
The 'd' is a Decimals transformation, with spaces prefix if needed ('D' is with zeros prefixed)
the '1' is a minimum of 1 digits before the decimal point (you can set to 0 if desired)
the '.2' is having 2 decimals after the decimal point, value is rounded.

The value is stored in a floating point format, so no information about the number of decimals is stored, that's to be specified when 'presenting' the value, hence the formatting and justification options are included in the variable retrieval.
Last edited by Ath on 22 Oct 2024, 07:38, edited 1 time in total.
/Ton (PayPal.me)

giorgino
Normal user
Posts: 126
Joined: 24 Oct 2022, 21:06

Re: a simple help on syntax

#7 Post by giorgino » 21 Oct 2024, 23:45

B-)


GREAT!!

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests