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 » U++ Library support » U++ Core » StrDbl and decimal separator
StrDbl and decimal separator [message #8854] Tue, 03 April 2007 19:00 Go to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

recently I had a bad experience during the parse of a file containing double under Linux. In fact the environment used the "," as decimal separator (very stupid Italian custom and maybe of some other country). So the program wrote its double with "," and successively StrDbl failed to read them. In fact
0,5 1,0 became as the integers 0 and 1. This produced weird results all around. The question is: how to avoid this misunderstanding?

Of course one is to say in advance to the user to set differently the decimal separator. But this is cumbersome because the user really need that stupid sign for other reason and switching each time is not good.

Perhaps it is enough to force the program to save its double with the "." irrispective of the environment. Is it possible?
Any other solution is welcome.

Luigi

PS: to read the numbers in the line :
0,5  1,0

I use Split because the numbers in the row may change. So I've in this case two strings to convert in double. Perhaps there is safer way to read them.
Re: StrDbl and decimal separator [message #8855 is a reply to message #8854] Tue, 03 April 2007 19:03 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
forlano wrote on Tue, 03 April 2007 19:00

Hello,

recently I had a bad experience during the parse of a file containing double under Linux. In fact the environment used the "," as decimal separator (very stupid Italian custom and maybe of some other country). So the program wrote its double with "," and successively StrDbl failed to read them. In fact
0,5 1,0 became as the integers 0 and 1. This produced weird results all around. The question is: how to avoid this misunderstanding?

Of course one is to say in advance to the user to set differently the decimal separator. But this is cumbersome because the user really need that stupid sign for other reason and switching each time is not good.

Perhaps it is enough to force the program to save its double with the "." irrispective of the environment. Is it possible?
Any other solution is welcome.

Luigi

PS: to read the numbers in the line :
0,5  1,0

I use Split because the numbers in the row may change. So I've in this case two strings to convert in double. Perhaps there is safer way to read them.


EDIT: Just now I found: String decimal_point
Is this the solution and how to use it?
Re: StrDbl and decimal separator [message #8875 is a reply to message #8855] Wed, 04 April 2007 19:11 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
I've found this piece of code in the library:
LanguageInfoCS::LanguageInfoCS()
: LanguageInfo(LNG_CZECH)
{
	english_name = "Czech";
	native_name = ToUnicode("Česky", CHARSET_WIN1250); // __FILE__CHARSET__
//	charset = CHARSET_WIN1250;
//	thousand_separator = L" ";
//	decimal_point = L",";
}

maybe even in CZECH it is used the "," as decimal separator. Because I need to exchange the files produced by windows and linux, it is important to freeze one time for all the internal representation of the decimal_point. So I am ready to modify the library and override, within my app, what the user has choosen before.
So the question is: how to set definitively the "." as decimal point for all kind of language?

It seems I've to intercept the following instrctions:
decimal_point = GetLocaleInfoA(lcid, LOCALE_SDECIMAL); //windows
decimal_point = lc->decimal_point; // linux

and set for both

decimal_point = ".";

is it enough or I am going to do weird things?
Thank you,
Luigi
Re: StrDbl and decimal separator [message #8893 is a reply to message #8875] Thu, 05 April 2007 18:54 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Last week, Tom has added "accept_comma" to

double        ScanDouble(const char *ptr, const char **endptr = NULL, bool accept_comma = true);
double        ScanDouble(const wchar *ptr, const wchar **endptr = NULL, bool accept_comma = true);


Hope this helps Smile

Mirek
Re: StrDbl and decimal separator [message #8895 is a reply to message #8893] Thu, 05 April 2007 19:30 Go to previous message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
luzr wrote on Thu, 05 April 2007 18:54

Last week, Tom has added "accept_comma" to

double        ScanDouble(const char *ptr, const char **endptr = NULL, bool accept_comma = true);
double        ScanDouble(const wchar *ptr, const wchar **endptr = NULL, bool accept_comma = true);


Hope this helps Smile

Mirek


The problem regarded an old version of the library. This new methods should do the job.
Thanks!

Luigi
Previous Topic: Unsafe Deep Copy
Next Topic: Value and Serialize
Goto Forum:
  


Current Time: Sun Apr 28 22:44:06 CEST 2024

Total time taken to generate the page: 0.91545 seconds