[SOLVED] Convert a string to float with one comma

Hello,

I have this rule Statement:

eg_bz_thermostat_soll.label = eg_bz_thermostat_ist.state.toString() + " °C IST Temp-> Soll [%.0f °C]"
with e.g. this output:
21.84 °C IST Temp->Soll 23 °C

Now I want, that the first number is only with one comma display, also ’ 21.8 °C IST Temp->Soll 23 °C’
How can I do this?
Thank you!

Please post the eg_bz_thermostat_ist item config or change it to add [%.1f °C] like below.

Number eg_bz_thermostat_ist "Some Name [%.1f °C]"

Number eg_bz_thermostat_ist {channel=“zwave:device:b3d3d4dc:node14:sensor_temperature”}

Try this:

Number eg_bz_thermostat_ist "[%.1f °C]" {channel=“zwave:device:b3d3d4dc:node14:sensor_temperature”}

For reference see here:

This show me the item name ‘eg_bz_thermostat_soll’ from the output from sitemap.

I think I need a function, that concert the string “21.84” to a number, than format it to 1 comma-digit (“21.8”) and then convert back to a string and concatenate with the rest of the string (“°C IST Temp-> Soll”)
It is possible?

Try this.

eg_bz_thermostat_soll.label = String::format("%.1f", (eg_bz_thermostat_ist.state as DecimalType).floatValue()) + " °C IST Temp-> Soll [%.0f °C]"

If the output is not what’s expected then add Grad. like below.

eg_bz_thermostat_soll.label = String::format("%.1f", (eg_bz_thermostat_ist.state as DecimalType).floatValue()) + " Grad." + " °C IST Temp-> Soll [%.0f °C]"
1 Like

Thank you, this works now fine!