[SOLVED] String:format - %%

Hi!
I can’t get the percent sign in the formatted string:

answer = String::format("*Climate:* \nBox: %.1f°C | %.0f %%", (box_climate_temp.state as Number).floatValue, (box_climate_humi.state as Number).floatValue)

log:

2019-11-29 13:38:12.711 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'test': Conversion = '%'

If you remove %%, it works:

answer = String::format("*Climate:* \nBox: %.1f°C | %.0f", (box_climate_temp.state as Number).floatValue, (box_climate_humi.state as Number).floatValue)

How to display a percent sign?
What am I doing wrong?
PS openHAB 2.5.0 Build #1764
Thanks!

What about just one %:

answer = String::format("*Climate:* \nBox: %.1f°C | %.0f %", (box_climate_temp.state as Number).floatValue, (box_climate_humi.state as Number).floatValue)
2019-11-29 19:16:06.195 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'test': Conversion = '

'

Shouldn’t it be more like
“Climate: \nBox: %1$.1f°C | %2$.0f %%”

%.0f and %2$.0f both options work.
%2$.0f %% and %2$.0f %

2019-11-29 19:16:06.195 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'test': Conversion = '

'

Tested on OH 2.4

var teststr = String::format("Climate: \nBox: %.1f°C | %.0f %%", 17.35, 65.00)
logInfo("test", teststr)
2019-11-30 02:05:09.689 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'doors.rules'
2019-11-30 02:05:19.256 [INFO ] [.eclipse.smarthome.model.script.test] - Climate: 
Box: 17.4°C | 65 %

Have you got any imports or something?

Fine!
Thanks for the help, the error is really not in the format.

rule "Send telegram with Fixed Message"
when
   Item TestTelegram changed to ON
then
    var teststr = String::format("Climate: \nBox: %.1f°C | %.0f %%", 
                        (box_climate_temp.state as Number).floatValue, 
                        (box_climate_humi.state as Number).floatValue)
    logInfo("test", teststr)
    val telegramAction = getActions("telegram","telegram:telegramBot:gbot")
    telegramAction.sendTelegram(teststr)
end

The problem is in telegramAction.sendTelegram(teststr)
It remains to find out why :frowning:

ahhhh you’ll need to escape or urlencode the single % in your string, I don’t know which but would try %%%% to begin with

That’s what comes of hiding the rule :wink:

It works, thanks friend! :slight_smile:

I agree completely, but it is very large, and I was sure that the format of the problem. Century live, Century study :smiley:
Thanks!