Board index » delphi » string to currency function.

string to currency function.

Hi,

Is there a string to currency function that handles currency symbols and
thousand seperators hidden in Delphi anyware?

Mat.

 

Re:string to currency function.


Actually thats what I did. Here's my code

function CurrStrToCurr(S: string): Currency;
begin
  Result := 0;
  S := Trim(S);
  S := StringReplace(S, CurrencyString, '', [rfReplaceAll, rfIgnoreCase]);
  S := StringReplace(S, ThousandSeparator, '', [rfReplaceAll,
rfIgnoreCase]);
  if S = '' then Exit;
  Result := StrToCurr(S);
end;

I just didn't want to go re-inventing the wheel so to speak, thats all.

Thanks anyway,

Mat.

Re:string to currency function.


Quote
"matthew" <matt...@datasym.co.uk> wrote in message

news:3c592de5$1_1@dnews...

Quote
> Hi,

> Is there a string to currency function that handles currency
symbols and
> thousand seperators hidden in Delphi anyware?

If so, it's not obvious in my D5 installation.  Would you
consider it sloppy to simply StringReplace commas and currency
symbols before using the standard StrToCurr function?  Once
you've determined the denomination of the currency, it's not
like those symbols carry any additional meaning.

Re:string to currency function.


Quote
"matthew" <matt...@datasym.co.uk> wrote in message

news:3c592de5$1_1@dnews...

Quote
> Hi,
> Is there a string to currency function that handles currency symbols and
> thousand seperators hidden in Delphi anyware?
> Mat.

    You can use following code:

    strCurrency := '$123,123.34';
    strCurrency := StringReplace( strCurrency, ThousandSeparator, EmptyStr,
[rfReplaceAll, rfIgnoreCase] );
    strCurrency := StringReplace( strCurrency, CurrencyString, EmptyStr,
[rfReplaceAll, rfIgnoreCase] );
    try
      Curr := StrToCurr( strCurrency );
    except
      Curr := 0;
    end

Regards,
Amir

Re:string to currency function.


Quote
> matthew" <matt...@datasym.co.uk> wrote in message

news:3c592de5$1_1@dnews...

Quote
> Hi,

> Is there a string to currency function that handles currency symbols and
> thousand seperators hidden in Delphi anyware?

Don't know what version of Delphi it appeared in, but in D6 there's the "%m"
specifier for the Format function; this incorporates symbols and settings
from [cut & paste] CurrencyString, CurrencyFormat, NegCurrFormat,
ThousandSeparator, DecimalSeparator, and CurrencyDecimals.

Other Threads