kriznik
(kriznik)
July 9, 2019, 7:51am
1
Hello,
another small question for my puzzle.
Is there a way how to do thousand separator different than “,” ??
I can do this easily in .items
Number PVE_Daily "Today's Yield [%,.0f Wh]"`
Which would give me instead of 22478 Wh 22,478 Wh but that’s US formatting and I would like to have it like 22 478 Wh
This is not working (do i need to somehow escape " " ?
Number PVE_Daily "Today's Yield [% .0f Wh]"`
And I’ve tried as well this in rules
String result = String.format("%,.2f", value).replace(",", " ");
which log rejected as "This expression is not allowed in this context, since it doesn’t cause any side effects. "
Thanks for tips!
(even better would be to have an ability to format all numbers automatically by locale - which is set in configuration)
rlkoshak
(Rich Koshak)
July 9, 2019, 5:59pm
2
kriznik
(kriznik)
July 9, 2019, 6:27pm
3
yes I know that, but as per documentation
‘,’ - - y2 y5 - The result will include locale-specific grouping separators
this is not the case in OH2 because it’s not using locale specific, but only US
rlkoshak
(Rich Koshak)
July 9, 2019, 6:47pm
4
Have you set your locale in OH? OH doesn’t actually change any of this. It uses that String formatter as is. There isn’t any way that it could override the documented behavior.
kriznik
(kriznik)
July 9, 2019, 6:55pm
5
yep I configured locale in paperUI but it seems formatter just ignore this and uses US default
rlkoshak
(Rich Koshak)
July 9, 2019, 7:03pm
6
What about the local on the operating system?
Given that a super majority of openHAB developers are European and the majority of openHAB users are European I find it unlikely they would hard code a US default anywhere in the software. There has to be some setting somewhere.
kriznik
(kriznik)
July 9, 2019, 8:55pm
7
locale is en_CA which should have " " as a separator
I’ll try 2.5 snapshot if it will be working correctly
rossko57
(Rossko57)
July 9, 2019, 9:32pm
8
kriznik:
locale is en_CA
But who’s locale? openHAB has one, but java has one too, which I imagine gets picked from host OS.
On my (windows) karaf console, the lengthy output from system:property
includes
user.country=GB
user.language=en
This chart gives , comma as separator for en_CA (Canada)
https://lh.2xlibre.net/locale/en_CA/
fr_CA on the other hand has space
According to this and this , the thousands separator is actually a comma for en_CA…
kriznik
(kriznik)
July 9, 2019, 11:08pm
10
hmm i was looking here
https://docs.oracle.com/cd/E19455-01/806-0169/overview-9/index.html
and separator there looks like space … so question is if java from oracle actually using their definition or whatever.
kriznik
(kriznik)
July 9, 2019, 11:32pm
11
so so i’ve changed locale to more europian, de_DE and separator is still the same
Number PVE_Daily "Today's Yield [%,.0f Wh]"
I guess this interpration simply using , as separator no matter which locale. Or can anybody confirm different result?
rossko57
(Rossko57)
July 10, 2019, 12:15am
12
If you enter
system:property
on the karaf console, what results do you see for
user.country=
user.language=
This is what I’d expect the formatter to use
kriznik
(kriznik)
July 10, 2019, 8:18am
13
user.country=DE
user.country.format=CA
user.language=de
user.language.format=en
strangely there is something .format which i have no idea where to change/how?
rossko57
(Rossko57)
July 10, 2019, 9:47am
14
humm, looks like the culprit. I had not thought of “sub-settings” at work. The .format
version will be used by the formatter only. Seems unlikely it got randomly set to CA. Sorry I do not how to alter, or better remove, these settings. Maybe something in ...openHAB/runtime/bin/setenv
kriznik
(kriznik)
July 10, 2019, 10:07am
15
thanks to your hint i was able to find where it is driven
so
user.country=DE
user.language=de
are from /etc/default/locale -> LC_MESSAGE
user.country.format=CA
user.language.format=en
are used from /etc/default/locale -> LANG
so yeah, messed up locales, but ironically messed up by openhabian-config tool
rossko57
(Rossko57)
July 10, 2019, 10:12am
16
Sneaky. What was fix, just edit the offending lines, remove them, or re-run the tool?
No openhabian here, presumably why I have no user.xxx.format
system settings (and formatter will use the base settings)
kriznik
(kriznik)
July 10, 2019, 10:23am
17
fix is pretty easy, just manually update locale and because I want english console but EU numbers etc. I did:
Edit /etc/locale.gen and make sure that both en_US.UTF-8 and regional eg. de_DE.UTF-8 are uncommented.
Run “sudo locale-gen”
Edit /etc/default/locale with this:
LANG=de_DE.UTF-8
LC_MESSAGES=en_US.UTF-8
fixed
and result from console is
user.country=US
user.country.format=DE
user.language=en
user.language.format=de
and btw OH 2.5 snapshot, dunno if that .format thing is in 2.4 as well
1 Like
rossko57
(Rossko57)
July 10, 2019, 10:42am
18
Reckon that would work with CA-en and CA-fr
rak
(Ralf Klüber)
July 10, 2019, 8:47pm
19
Well spotted. Will implement as well.
kriznik
(kriznik)
July 10, 2019, 10:07pm
20
well I think this should not depend on system locale but trully only on OH locale, as many of us are using linux machines as en_US preferably, but end-user apps like OH should act as system independed with their own lang settings
just my two cents ;]