Disable float/string localization on Linux?

BlitzMax Forums/BlitzMax Programming/Disable float/string localization on Linux?

JoshK(Posted 2014) [#1]
How can I disable localization of info on Linux? My application is saving floating-point numbers with commas instead of periods in some regions and it is causing problems.


ziggy(Posted 2014) [#2]
Is this happening at data conversion level or in the serialization of data? Maybe you could use the locale of std http://en.cppreference.com/w/c/locale/setlocale Maybe the internal streams are being format. You can also expect to have the minus sing at the right of the numbers on several regions.


JoshK(Posted 2014) [#3]
Since I live in the U.S. I really have no idea where this occurs. I think it's in the String() and Float() functions. All I know is that my users in some areas are having problems because my config file is getting stuff like "0,25" written to it instead of "0.25".

I can work around this for files that are only for their machine, like a settings file, but our material files are ASCII based. If they save materials files, they won't work right on other computers.


Yasha(Posted 2014) [#4]
String() uses sprintf internally, so I guess this is SO question is describing the same problem: http://stackoverflow.com/questions/3709886/sprintf-commas-and-dots-in-c-and-localization

i.e. add a call to setlocale right before the data is written/serialized?

For that matter, to test the issue yourself, you could try simply adding a setlocale to German in initialization to force the "wrong" behaviour, regardless of your system. (demonstrated in the official example)


*(Posted 2014) [#5]
You normally find the characters are in the euro zone countries like the Netherlands and Germany where things a like 24.00 for us becomes a 24,00.

I always found it weird tbh but a quick replace on the string if the comma is surrounded by numbers seemed to help in most cases.


ziggy(Posted 2014) [#6]
There are more things that can change on locales, such as negative sign placement: in ex. 45,78- is the same as -45.78 so I would highly recommend you to do what Yasha suggested just as the first sentence in your application. If it's not ready to support non US configurations (that's sad), you should modify the locale the whole application so everything is shown the same everywhere.


dawlane(Posted 2014) [#7]
You will have to do a bit of editing in blitz_string.c. See here for setting the locale.


JoshK(Posted 2014) [#8]
Here's what I did at the start of my program:
Extern
Function setlocale(category:Int,locale$z)
EndExtern
setlocale(0,"en-us")



ziggy(Posted 2014) [#9]
I think this should do it. I thought it was en-US, but not sure.


Derron(Posted 2014) [#10]
Are you sure "setlocale" is available on all systems?

On my NAS I had trouble to get setLocale working - as some binaries werent compiled with support of it.

So it _might_ fail.


bye
Ron


ziggy(Posted 2014) [#11]
It's already using it (otherwise he won't be having the problems he has) so I'm sure it's available in current scenario.
Additionally, AFAIK I think it is something that does not have to be available at the OS level, as the STD implementation of set locale will use a default english version of itself in case the setLocale fails (at the OS api level), so even if it does not work, it should provide expected results, as at the end, it'll be formatting text in english US notation