Lazarus

Programming => General => Topic started by: pik33 on August 24, 2010, 08:06:45 am

Title: How to get rid of locale settings in strtofloat?
Post by: pik33 on August 24, 2010, 08:06:45 am
I am writing a interpreter for music programming language. So it has to read program line, for example, "play 1,330.125", where 1 is channel number and 330.125 is frequency in Hz.

When I recompiled this under Polish version of Windows XP, I got exception: 330.125 is not a float!!!!!
In (also Polish localized) OpenSuse 11.2 x64 it works.

In Windows PL proper float is 330,125, not 330.125

I don't want program sources to be localized (!!!!!) and dependent on installed OS.

So, I wrote my own function strtofloat, which do its job regardless of locale settings... but I have a question: is it possible to use original strtofloat function, and, if it is possible, how to do it?
Title: Re: How to get rid of locale settings in strtofloat?
Post by: faber on August 24, 2010, 08:30:32 am
It's depend on separator from system settings. If you have ',' as separator you must change DecimalSeparator
http://www.freepascal.org/docs-html/rtl/sysutils/decimalseparator.html
Title: Re: How to get rid of locale settings in strtofloat?
Post by: JohnvdWaeter on August 24, 2010, 08:51:57 am
Hi,

.. or simply use the str() and the val() functions.

John
Title: Re: How to get rid of locale settings in strtofloat?
Post by: felipemdc on August 24, 2010, 12:23:12 pm
I documented the solution to this problem here:

http://wiki.freepascal.org/Multiplatform_Programming_Guide#Locale_differences

Despite the fact that it was already documented in the RTL docs
Title: Re: How to get rid of locale settings in strtofloat?
Post by: marcov on August 25, 2010, 03:17:21 pm
On win32/win64 and 2.5.1+, you can also use

procedure GetLocaleFormatSettings(LCID: Integer; var FormatSettings: TFormatSettings);

to load the locale that you want into tformatsettings.
TinyPortal © 2005-2018