[SOLVED] Formatting Numbers from Items

Hello,

i thing that i have tried all, but it do not work till now.
Please advice me how to work with numbers from items?
I would like to format temperature to whole numbers without commas.

Group:Number:AVG  gMaxAVGTemperature "Average Temperature [%.1f °C]" // e.g. "21.3 °C
rule "Status. Clima"
when
   Item gMaxAVGTemperature changed
then
    logInfo("loggerName", String.format("%,.0f", gMaxAVGTemperature.state))
end

These do not works:

  String.format("%,.0f", gMaxAVGTemperature.state.intValue)
  String.format("%,.0f", gMaxAVGTemperature.state as Number)
  String.format("%,.0f", gMaxAVGTemperature.state as DecimalType)
  String.format("%,.0f", gMaxAVGTemperature.state.toString.IntValue)
and so on..

Thanks a lot!

%d

1 Like

Thanks a lot Rich, but

LogInfo("loggerName", String.format("%d,.0f", gMaxAVGTemperature.state))

i get the same

2020-01-28 19:03:40.004 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Status. Clima': d != org.eclipse.smarthome.core.library.types.DecimalType


No, replace all of the formatting stuff with %d.

format("%d", gMax...
1 Like

Again (((

  logInfo("loggerName", String.format("%d", gMaxAVGTemperature.state))

I also can not understand it(((

2020-01-28 19:07:28.003 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Status. Clima': d != org.eclipse.smarthome.core.library.types.DecimalType


String.format("%d", gMaxAVGTemperature.state as DecimalType)

I’m not too clear why you keep putting commas in your other formats

String.format("%.0f", gMaxAVGTemperature.state as Number)

1 Like

Thanks but the same error with or without comma (((
Normally

   logInfo("loggerName", "temp " + gMaxAVGTemperature.state)

i have in this variable

2020-01-28 20:45:40.003 [INFO ] [se.smarthome.model.script.loggerName] - temp 23.3

Can not undertand the simple thing(((

Works for me -

logInfo("loggerName", "temp " + gMaxAVGTemperature.state.format("%.0f"))

Thanks a lot!
Now it works!

I have a question to this…how can i make a percent-sign appear on the label? For Example: [%.1f °C] displays degree celsius, but [%.1f %] leads to error…I want to display the humidity in percent…

Double % e.g.
[%.1f %%]

1 Like

Omg thanks! It’s working :-))) looked eternally for it XD