Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-06

Problem with StrToCurrDef()

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

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

Reply by email

silvioprog
to LacaK

2014-06-05 5:16 GMT-03:00 LacaK :

Show quoted text 12 lines
silvioprog wrote / napísal(a): 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: > See: http://www.freepascal.org/docs-html/rtl/sysutils/strtocurr.html Or: http://docwiki.embarcadero.com/VCL/XE/en/SysUtils.StrToCurr Currency symbol is not allowed in given string. -Laco.

Solved. Thanks a lot for this information Laco! :-)

Silvio Clécio My public projects - github.com/silvioprog

Reply by email