Re:floats
Quote
"James Hettinger" <j...@hotmail.com> wrote in message
news:7xXk6.10656$4q3.390380@news1.telusplanet.net...
Quote
> I've diplayed a float in a stingGrid with floatToStrF(.....,ffcurrency)
wich
> displays $1,200.00
> Reconverting it back doesn't work too well.....even just using copy and
> leaving the $ out, it still doesn't like the comma..
> Suggestions?
You're better off using Format with a money code and then clearing all
characters except numbers and the decimal separator from the string when you
convert back. Then you cater for any other local currency and currency
position.
Label1.Caption := Format('%7.2m' , [123456.784]);
. . . produces 123,456.78 for me and most likely $123,456.78 for you and
possibly 123,456.78 $ for some other country which puts the currency sign after
the numbers. Then recover the amount with . . .
function StringToFloat(S : string) : single;
var
i, j : integer;
TmpStr : string;
begin
SetLength(TmpStr, Length(S));
j := 1;
for i := 1 to Length(S) do
if S[i] in ['-','0'..'9', DecimalSeparator] then begin // that's a good
character
TmpStr[j] := S[i];
inc(j);
end;
SetLength(TmpStr, j - 1);
Result := StrToFloat(TmpStr);
end;
Alan Lloyd
alangll...@aol.com