Olymp
(Sergey M)
November 29, 2019, 5:49am
1
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!
vzorglub
(Vincent Regaud)
November 29, 2019, 11:01am
2
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)
Olymp
(Sergey M)
November 29, 2019, 11:16am
3
vzorglub:
What about just one %:
2019-11-29 19:16:06.195 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'test': Conversion = '
'
rossko57
(Rossko57)
November 29, 2019, 11:36am
4
Shouldn’t it be more like
“Climate: \nBox: %1$.1f°C | %2$.0f %%”
Olymp
(Sergey M)
November 30, 2019, 1:23am
5
%.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 = '
'
rossko57
(Rossko57)
November 30, 2019, 2:08am
6
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?
Olymp
(Sergey M)
November 30, 2019, 2:47am
7
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
rossko57
(Rossko57)
November 30, 2019, 2:50am
8
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
Olymp
(Sergey M)
November 30, 2019, 6:20am
9
rossko57:
try %%%%
It works, thanks friend!
I agree completely, but it is very large, and I was sure that the format of the problem. Century live, Century study
Thanks!