Subject Re: [ib-support] to change the decimal separator
Author aandea_launch
Hello Alexandre ,

The danger in using this function :

function FloatToStrSQL(D:Extended):String;
var
wDecimalSeparator:Char;
begin
wDecimalSeparator := DecimalSeparator;
DecimalSeparator := '.'
try
Result := FloatToStr(D);
finally
DecimalSeparator := wDecimalSeparator;
end;
end;

is in multi-threaded envrionments, where one thread might set the
separator back before you are doing the conversion in other thread...




--- In firebird-support@yahoogroups.com, Alexandre Benson Smith
<iblist@...> wrote:
>
> Robert martin wrote:
> > Hi
> >
> > I have never used the code you have here but it looks dangerous to
me.
> > Why not just use the following (if you are going to hard code the
> > decimal separator).
> >
> > Result := FormatFloat('##0.00', D);
> >
> >
> > Rob Martin
> > Software Engineer
> >
>
> Why dangerous ?
>
> Because if i dont specify that the DecimalSeparator should be "."
Delphi
> uses the Windows Locale Seetings, that in Brazil is defined to use
Comma
> as Decimal Separator, so the result of
>
> FormatFloat('##0.00', 123.45)
>
> will be 123,45 that is the exactly problem that started this thread.
>
> Off course parameters are preferred.
>
> but in the function e wrote (without exception handling and just as
an example)
> the result will be
> 123.45 no matter how DecimalSeparator as set on Windows Locale Settings.
>
> see you !
>
>
> --
> Alexandre Benson Smith
> Development
> THOR Software e Comercial Ltda
> Santo Andre - Sao Paulo - Brazil
> www.thorsoftware.com.br
>