Hi Mark,
The simple way would seem to be to allow for this particular case, like so:
Value := StrToFloat(StringReplace(Text, '-$', '$-', []));
If there is the possibility of spaces lurking around, you could also Trim the
string. Admittedly, this adds overhead and only covers one specific case that
doesn't convert for you, but if this looks like the only format that needs
fixing then this is a fairly simple fix.
Actually, you could drop the dollar sign from the replacement substring
altogether, and make the job easier for the StrToFloat function. In fact, you
could just substitute '$' for null string then StrToFloat it, although that
wouldn't care about malformed text values like '123$45'.
Cheers
Pedrocelli
----- Original Message -----
From: "Mark Howard" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, April 27, 2004 3:10 PM
Subject: [DUG] StrToFloat
Hi All
I want to be able to convert a string to floating point where the string is in
the form
either $245.45
OR -$242.45
The first one converts OK but the second one come up with "-$242.45 is not a
valid
floating point value.
The Delphi help says:
"Category
floating point conversion routines
Delphi syntax:
function StrToFloat(const S: string): Extended; overload;
function StrToFloat(const S: string; const FormatSettings: TFormatSettings):
Extended; overload;"
AND
"Delphi syntax:
type
TFormatSettings = record
CurrencyFormat: Byte;
NegCurrFormat: Byte;
ThousandSeparator: Char;"
But if I use
StrToFloat('-$242.45', NegCurrFormat)
I get a message saying "there is on overloaded version of StrToCurr that can be
used with these arguments."
Is someone able to help, please?
TIA
Mark
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi
_______________________________________________
Delphi mailing list
[EMAIL PROTECTED]
http://ns3.123.co.nz/mailman/listinfo/delphi