temperature = (mytempitem.state as Number).floatValue
This works but in other topics I found this:
temperature = (mytempitem.state as Number).doubleValue
Does this make any difference or is one better than the other?
I have also read about bigDecimal, but don’t know how to use them.
Is there a best conversion for a number:temperature item to a number variable?
at the end all type casts are depending on what you like to achieve. For temperature values in my opinion there is no real difference but float should be sufficient. Typically temperature are somthing like 12,5°C and the precision should be enough.
Technically, if you use the previous methods you’ll get a numeric in whatever units the Item happens to hold at the time.
There are ways to ensure you get exactly what you want, i.e. force the value into C say
var YourNumericInC = (yourTempItem.state as QuantityType<Temperature>).toUnit("°C").toBigDecimal
but in general it is better to do your maths using quantities with units, rather than trying to isolate the numeric part only.