Formatting items in rules to generate a string

I found the solution at the very end of this post.

String formatting

I want “21.3°C” in my message string, not “21.28478 °C”

var message = "Temperature is " + (tempItemC.state as QuantityType<Temperature>).format("%.1f%unit%")
// returns "Temperature is 10.0°C"
// uses usual Java formatter control string

for speed you can use

+(localTodayWindSpeed.state as QuantityType<Speed>).format("%.1f %unit%")
2 Likes