[SOLVED] String formatting in a rule of numbers

(Psyciknz) #1

I’ve got a description value I’m trying to create
heating_morning_description.postUpdate(String::format("Morning: Time on: %s Time off: %s Max Temp: %1s °C",heating_morning_time_on.state,heating_morning_time_off.state,max))

max is a var Number (only done because leaving just the item .state or putting item .state as DecimalType wouldn’t work.
So as it stands, the max value in the description becomes: 18.199999999999985 °C
I’d like to push that down to 1 decimal place.

I’ve tried Max Temp: %f and get f != org.eclipse.smarthome.core.library.types.DecimalType
I’ve tried Max Temp: %d and get d != org.eclipse.smarthome.core.library.types.DecimalType

Where am I going wrong?

0 Likes

(Psyciknz) #2

Ahh I got it, I changed the definition of max from
var Number max = ((heating_morning_maximum_setpoint.state) as DecimalType)
to

var Number max = ((heating_morning_maximum_setpoint.state) as DecimalType).floatValue

and it worked as now it’s a float. I would have thought that DecimalType was already a float type

1 Like

(Udo Hartmann) #3

float is a decimal type - and integer is also…

0 Likes

(SiHui) #4

Thx, worked for me too :+1:

0 Likes