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.
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?
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