[fpc-pascal] Problem with StrToCurrDef()

silvioprog silvioprog at gmail.com
Wed Jun 4 22:51:00 CEST 2014


Hello,

I'm trying to convert 'curr > str' and 'str to curr' respectively, but I've
got a problem with StrToCurrDef(). See my test below:

var
  s: string;
  c: Currency;
begin
  c := 150.49;
  s := CurrToStrF(c, ffCurrency, 2);
  ShowMessage('OK: ' + s); // shows R$ 150,49

  c := StrToCurrDef('R$ 150,49', 0);
  s := CurrToStrF(c, ffCurrency, 2);
  ShowMessage('Fail: ' + s); // shows R$ 0,00, I expected R$ 150,49
end;

I tried it too:

  DefaultFormatSettings.CurrencyString := 'R$';
  DefaultFormatSettings.DecimalSeparator := ',';
  DefaultFormatSettings.ThousandSeparator := '.';
  c := StrToCurrDef('R$ 150,49', 0, DefaultFormatSettings);

But the same problem happened, 'c' = 0.

What is the best way to solve it? I have a way out, it would be this code
below, but I wonder if there is something in the FCL, not to need to create
this 'SomeFuncToRemoveAlphaChars' function:

  v := SomeFuncToRemoveAlphaChars('R$ 150,49'); // only 150,49
  c := StrToCurrDef(v, 0, DefaultFormatSettings);
  s := CurrToStrF(c, ffCurrency, 2); // now it shows R$ 150,49

Thank you!

-- 
Silvio Clécio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20140604/e27dd7a0/attachment.html>


More information about the fpc-pascal mailing list