Lazarus
Programming => General => Topic started 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?
-
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
-
Hi,
.. or simply use the str() and the val() functions.
John
-
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
-
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.