Recent

Author Topic: How to get rid of locale settings in strtofloat?  (Read 6824 times)

pik33

  • Jr. Member
  • **
  • Posts: 76
How to get rid of locale settings in strtofloat?
« 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?

faber

  • Guest
Re: How to get rid of locale settings in strtofloat?
« Reply #1 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

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 171
    • http://www.jvdw.nl
Re: How to get rid of locale settings in strtofloat?
« Reply #2 on: August 24, 2010, 08:51:57 am »
Hi,

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

John

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
Re: How to get rid of locale settings in strtofloat?
« Reply #3 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

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11445
  • FPC developer.
Re: How to get rid of locale settings in strtofloat?
« Reply #4 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