Via the serial inteface I get a string with hexadecimal values of a sensor.
Now I’m having trouble converting the String to a float which shall be used for further calculations.
For testing purposes this calculation is a division by 100 which should result in an integer with some decimals.
Number nSensorVal "val= [%.2f]"
var Number nIntVal var Number nFloatVal nIntVal = Integer::parseInt(sHexString, 16) // this works! nFloatVal = ??? / 100 // no idea what to put here nSensorVal.postUpdate(nFloatVal)
In place of ??? I’ve unsucessfully tried using things like
nFloatVal = Float::parseFloat(nIntVal.state)
nFloatVal = (nIntVal.state as DecimalType) / 100
I get a lot of errors like
The name ‘XFeatureCallImplCustom.state’ cannot be resolved to an item or type.
which to my knowledge indicates a type mismatch.
So how is an integer value converted to float to preserve decimal places when doing calculations?
Maybe that’s even possible in a single step?