Converting String to Double not working

Hello all,

Imagine that I have the following code:
rule “LoraServer”
Item Lora_rec received update
var String[] buffer= Lora_rec.state.toString.split(",")
var Number calc=new Float(buffer.get(1))
// until here all ok, imagine that calc= 1254
// here calc showld be 12.54 but its 13 (round of 12.54)
postUpdate(LoraD01001Ana1, calc)

What I neet is the float value of the calc that should be 12.54 not the int 13


I’d try
var Number calc= Float:parseFloat(buffer.get(1))

After 2 days found the problem :frowning:
In the rule everithing was ok but the variable was defined as:
Number LoraD01001Ana1 “Valor Lido 1 [%d]”

and clearly should be:
Number LoraD01001Ana1 “Valor Lido 1 [%.2f°C]”

… getting old :slight_smile:

By the Way is better to use:
var Number calc= Float:parseFloat(buffer.get(1))
Instead of:
var Number calc=new Float(buffer.get(1))

Thanks and sorry…

Sounds like the advice from every rules problem holds true - use logInfo() to see the value of suspect variables.