PLEG - Condition logic request

Hi Richard,

How feasible would it be to include some additional functionality in the Condition part of PLEG to include INTeger formatting (specific to X decimal places) ?

I have a few examples where a routine is performing a calculation on various inputs, the results often end up with long digits after the decimal which is both difficult to then handle and compare and also messy. Would be useful to have a function such as INT that could be called e.g. INT(10/3),2 would equal 3.33 instead of 3.333333333333333333

Cheers

David

I have had the same problem. There are 2 solutions:

In action I have a variable which I want to display with only 2 digits in my Multi String device, I am using this:

local kWhR = string.format(“%0.2f”, KWH.state)
luup.variable_set(“urn:micasaverde-com:serviceId:EnergyMetering1”, “KWH”,kWhR,(device id))

I asked about doing that in PLEG, and RexBeckett came up with this (taken from this thread :[url=http://forum.micasaverde.com/index.php/topic,31754.msg231264.html#msg231264]http://forum.micasaverde.com/index.php/topic,31754.msg231264.html#msg231264[/url]):

[quote=“RexBeckett, post:47, topic:186888”]X % 1 gives the remainder of dividing X by 1 - so the fractional part. X - (X % 1) is therefore the integer part of X. You can use it for rounding if you add 0.5: (X + 0.5) - ((X + 0.5) % 1).

You can also use it with a decimal modulus so you could get your two decimal places using:

(X + 0.005) - ((X + 0.005) % 0.01)[/quote]

Adding functions to the syntax has been an outstanding request.
It’s a lot of work … and a non ending source of request to support yet another function.

Nice work Rex, Mike - there’s always a workaround eh ?

Richard - don’t burden your list with another request, it’s a nice to have, but speed, memory usage and simplicity is better than functionality, esp. as the workaround is possible.

Cheers

David