Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2009-07

"VAL" and i18n

7 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jonas Maebe
to Torsten Bonde Christiansen
Torsten Bonde Christiansen wrote
After fiddling around with some local text i came across something odd. Is it true that the "val" function does not care for person i18n settings?

Yes.

Show quoted text 5 lines
Trying to validate "1,2" (notice the comma - danish decimal separtor style) with val resulted in returning code = 2, i.e. that comma is the problem. Stepping through the code, it seem that in "fpc_Val_Real_ShortStr" the decimal separator is hardcoded to ".". Is this a bug or is this just the way "val" is intended to work?

It is the way val is intended to work. Use http://www.freepascal.org/docs-html/rtl/sysutils/floattostr.html instead if you want to make use of the locale settings (do not forget to use the "clocale" unit in your program if you are on a Unix platform to initialise the locale settings, or manually specify a TFormatSettings parameter to floattostr).

Jonas

Jonas Maebe
to Jonas Maebe
Jonas Maebe wrote 7 lines
> Trying to validate "1,2" (notice the comma - danish decimal > separtor style) with val resulted in returning code = 2, i.e. that > comma is the problem. Stepping through the code, it seem that in > "fpc_Val_Real_ShortStr" the decimal separator is hardcoded to ".". > Is this a bug or is this just the way "val" is intended to work? It is the way val is intended to work. Use http://www.freepascal.org/docs-html/rtl/sysutils/floattostr.html

Oops, it's http://www.freepascal.org/docs-html/rtl/sysutils/strtofloat.html of course. Or http://www.freepascal.org/docs-html/rtl/sysutils/trystrtofloat.html if you don't want an exception if the conversion fails.

Jonas

Torsten Bonde Christiansen
to Jonas Maebe
Show quoted text 5 lines

It look like "Function TryStrToFloat(Const S : String; Out Value: Extended): Boolean" (extended version) is not documented. Is this because it's a 2.3.1 function or because it is not posible on all CPU's?

-Torsten.

Jonas Maebe
to Torsten Bonde Christiansen
Torsten Bonde Christiansen wrote 6 lines
> > Oops, it's http://www.freepascal.org/docs-html/rtl/sysutils/strtofloat.html > of course. Or http://www.freepascal.org/docs-html/rtl/sysutils/trystrtofloat.html > if you don't want an exception if the conversion fails. It look like "Function TryStrToFloat(Const S : String; Out Value: Extended): Boolean" (extended version) is not documented.

http://www.freepascal.org/docs-html/rtl/sysutils/trystrtofloat.html

Jonas

Jonas Maebe
to Torsten Bonde Christiansen: It look like "Function TryStrToFloat(Const S : String; Out Value: Extended): Boolean" …
Torsten Bonde Christiansen wrote
It look like "Function TryStrToFloat(Const S : String; Out Value: Extended): Boolean" (extended version) is not documented. Is this because it's a 2.3.1 function or because it is not posible on all CPU's?

Sorry, the latter. It's between an {$ifdef FPC_HAS_TYPE_EXTENDED}, which probably makes the code documenter skip it.

Jonas

Michael Van Canneyt
to Jonas Maebe
Jonas Maebe wrote 9 lines
On 24 Jul 2009, at 10:30, Torsten Bonde Christiansen wrote: > It look like "Function TryStrToFloat(Const S : String; Out Value: > Extended): Boolean" (extended version) is not documented. Is this because > it's a 2.3.1 function or because it is not posible on all CPU's? Sorry, the latter. It's between an {$ifdef FPC_HAS_TYPE_EXTENDED}, which probably makes the code documenter skip it.

I'll adapt the documentation generator so it enables these defines. There is also single, comp and maybe even some others.

Michael.