<div dir="ltr"><div>Hello,</div><div><br></div><div>I'm trying to convert 'curr > str' and 'str to curr' respectively, but I've got a problem with StrToCurrDef(). See my test below:</div><div><br>
</div><div>var</div><div> s: string;<br></div><div> c: Currency;</div><div>begin</div><div> c := 150.49;</div><div> s := CurrToStrF(c, ffCurrency, 2);</div><div> ShowMessage('OK: ' + s); // shows R$ 150,49</div>
<div><br></div><div> c := StrToCurrDef('R$ 150,49', 0);</div><div> s := CurrToStrF(c, ffCurrency, 2);</div><div> ShowMessage('Fail: ' + s); // shows R$ 0,00, I expected R$ 150,49</div><div>end;</div><div>
<br></div><div>I tried it too:</div><div><br></div><div> DefaultFormatSettings.CurrencyString := 'R$';</div><div> DefaultFormatSettings.DecimalSeparator := ',';</div><div> DefaultFormatSettings.ThousandSeparator := '.';</div>
<div> c := StrToCurrDef('R$ 150,49', 0, DefaultFormatSettings);</div><div><br></div><div>But the same problem happened, 'c' = 0.</div><div><br></div><div>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:</div>
<div><br></div><div> v := SomeFuncToRemoveAlphaChars('R$ 150,49'); // only 150,49</div><div> c := StrToCurrDef(v, 0, DefaultFormatSettings);</div><div> s := CurrToStrF(c, ffCurrency, 2); // now it shows R$ 150,49</div>
<div><br></div><div>Thank you!</div><div><div><br></div>-- <br>Silvio Clécio<br>My public projects - <a href="http://github.com/silvioprog" target="_blank">github.com/silvioprog</a>
</div></div>