Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » OS Problems etc., Win32, POSIX, MacOS, FreeBSD, X11 etc » localized formating of double on linux
localized formating of double on linux [message #19657] Tue, 30 December 2008 11:33 Go to next message
lokki is currently offline  lokki
Messages: 20
Registered: November 2005
Promising Member
Hello,

I'm porting application developed in UPP on Windows to Linux (using Gentoo 2008.1).

When formating double values (displayed in GridCtrl, in EditDouble), strage output appears. Following converter worked on windows but gives strange results on linux
class ConvertMoney : public ConvertDouble
{
public: ConvertMoney() : ConvertDouble() {Pattern("%2!nl");}
};

e.g. whe we have in database value 1.234, on windows is displayed string "1,23", on linux "1,00". It always changes last two charactes with zeros. Experimenting with converter's pattern gives no acceptable results.

My linux locale is:
LANG=sk_SK.utf8
LC_CTYPE=sk_SK.utf8
LC_NUMERIC="sk_SK.utf8"
LC_TIME="sk_SK.utf8"
LC_COLLATE=C
LC_MONETARY="sk_SK.utf8"
LC_MESSAGES="sk_SK.utf8"
LC_PAPER="sk_SK.utf8"
LC_NAME="sk_SK.utf8"
LC_ADDRESS="sk_SK.utf8"
LC_TELEPHONE="sk_SK.utf8"
LC_MEASUREMENT="sk_SK.utf8"
LC_IDENTIFICATION="sk_SK.utf8"
LC_ALL=

At the begining of code, the laguage is set:
int language = LNGC_('S','K','S','K', CHARSET_UTF8);
SetLanguage(language);

Database is Postgresql 8.3,

Thanks in advance for any clue.
Re: localized formating of double on linux [message #19659 is a reply to message #19657] Tue, 30 December 2008 16:25 Go to previous messageGo to next message
cocob is currently offline  cocob
Messages: 156
Registered: January 2008
Experienced Member
gtk_init() change libc behaviour according to locale setting.

I use this to remove the problems

setlocale(LC_ALL,"C");
Re: localized formating of double on linux [message #19660 is a reply to message #19659] Tue, 30 December 2008 16:59 Go to previous messageGo to next message
lokki is currently offline  lokki
Messages: 20
Registered: November 2005
Promising Member
Thanks a lot. Looks like it works now Smile
Re: localized formating of double on linux [message #19667 is a reply to message #19660] Sat, 03 January 2009 12:21 Go to previous messageGo to next message
lokki is currently offline  lokki
Messages: 20
Registered: November 2005
Promising Member
Hello,

bad news Sad

As posted previously, on Gentoo it works fine (development machine). Now trying to run Gentoo built executable on Ubuntu 10.8 ("production" machine). Same problem, the workaround for Gentoo doesn't work on Ubuntu. Don't know why, because locale on Ubuntu is set to:

LANG=sk_SK.UTF-8
LC_CTYPE="sk_SK.UTF-8"
LC_NUMERIC="sk_SK.UTF-8"
LC_TIME="sk_SK.UTF-8"
LC_COLLATE="sk_SK.UTF-8"
LC_MONETARY="sk_SK.UTF-8"
LC_MESSAGES="sk_SK.UTF-8"
LC_PAPER="sk_SK.UTF-8"
LC_NAME="sk_SK.UTF-8"
LC_ADDRESS="sk_SK.UTF-8"
LC_TELEPHONE="sk_SK.UTF-8"
LC_MEASUREMENT="sk_SK.UTF-8"
LC_IDENTIFICATION="sk_SK.UTF-8"
LC_ALL=


I tried to modify workaround a for whole locale configuration:
...
setlocale(LC_COLLATE,"sk_SK.UTF-8");
setlocale(LC_MONETARY,"sk_SK.UTF-8");
setlocale(LC_MESSAGES,"sk_SK.UTF-8");
...
setlocale(LC_ALL,"C");

But this doesn't help at all.

Thanks for any suggestions
Re: localized formating of double on linux [message #19668 is a reply to message #19657] Sat, 03 January 2009 14:57 Go to previous messageGo to next message
cocob is currently offline  cocob
Messages: 156
Registered: January 2008
Experienced Member
do you use setlocale(LC_ALL,"C"); after GUI initialization ?
Re: localized formating of double on linux [message #19669 is a reply to message #19668] Sat, 03 January 2009 15:09 Go to previous messageGo to next message
lokki is currently offline  lokki
Messages: 20
Registered: November 2005
Promising Member
Hello,

I don't know when the GUI is initialised exactly. I set language and locale in first lines of GUI_APP_MAIN. The code looks like this...
GUI_APP_MAIN
{	
	int language = LNGC_('S','K','S','K', CHARSET_UTF8);
	SetLanguage(language);
	setlocale(LC_ALL,"C");
....


edit: So it is executed before the main window is instantiated and run.

[Updated on: Sat, 03 January 2009 15:12]

Report message to a moderator

Re: localized formating of double on linux [message #19671 is a reply to message #19657] Sun, 04 January 2009 11:55 Go to previous messageGo to next message
cocob is currently offline  cocob
Messages: 156
Registered: January 2008
Experienced Member
I think this is the problem.

In my app i use setLocal in my main window constructor
Re: localized formating of double on linux [message #19687 is a reply to message #19671] Mon, 05 January 2009 20:11 Go to previous messageGo to next message
lokki is currently offline  lokki
Messages: 20
Registered: November 2005
Promising Member
OK, tried and didn't work.

I'm going to investigate it furher, but I'm very surprised. I wouldn't believe such thigs can happen between two unix systems (running same executable/source).

Looks to me, like I have something set up differently according to localization in Ubuntu (I checked locale variables, but don't know what else to check.. libc version??...)

Thanks for help cocob, in Gentoo it works perfectly (but not Ubuntu).
Re: localized formating of double on linux [message #19688 is a reply to message #19671] Mon, 05 January 2009 20:48 Go to previous messageGo to next message
lokki is currently offline  lokki
Messages: 20
Registered: November 2005
Promising Member
deleted (duplicate message)

[Updated on: Mon, 05 January 2009 20:49]

Report message to a moderator

Re: localized formating of double on linux [message #19913 is a reply to message #19657] Sun, 01 February 2009 18:37 Go to previous messageGo to next message
lokki is currently offline  lokki
Messages: 20
Registered: November 2005
Promising Member
Hello,

just to let you know, after experimenting with Ubuntu, I didn't find any solution of this problem. Switching production environment to Open SUSE 11.1 running KDE helped. Probably GNOME on Ubuntu was causing the problem some way, I wasn't able to resolve. Devel Gentoo was running KDE as well, that's why I think this way. Development machine was swithced to Open SUSE afterwards as well.
Re: localized formating of double on linux [message #27352 is a reply to message #19913] Tue, 13 July 2010 22:18 Go to previous message
zsolt is currently offline  zsolt
Messages: 590
Registered: December 2005
Location: Budapest, Hungary
Contributor
Put an extra line into /etc/locale.alias:
sk_SK   sk_SK.UTF-8

and run the command
locale-gen

from console.

I think it would be better to fix this in UPP code and trying locale with ".UTF-8" suffix when "sk_SK" type locale didn't succeed.
Previous Topic: Huge amount of linking errors [FreeBSD 7.1, GCC 4.3]
Next Topic: MSVC++ Runtime error
Goto Forum:
  


Current Time: Wed Nov 20 05:27:22 CET 2019

Total time taken to generate the page: 0.01283 seconds