Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Fields[i].AsCurrency := StrToCurr('$1,569.34');

Posted on 2002-04-19
6
Medium Priority
?
677 Views
Last Modified: 2010-04-04
There has to be a simple way to do this that I am missing?

Of course one could strip out the '$' and ',' in code, it just seems those brilliant bunch of folks at Borland would have provided for this eventuality.

Thanx in andvance,

Greg
0
Comment
Question by:Greg Rowland
  • 4
  • 2
6 Comments
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6954723
From the Delphi help file:

The DecimalSeparator global variable defines the character that is used as a decimal point. Thousand separators and currency symbols are not allowed in the string. If the string doesn't contain a valid value, StrToCurr raises an EConvertError exception.

0
 
LVL 6

Accepted Solution

by:
DrDelphi earned 100 total points
ID: 6954793
Try this out for size instead:


Function StrToCurrEX(str:string;Delimiter:char;denominator:char):string;
var tempstr:string;
    Dollarsign,Comma:integer;
begin
   Tempstr:=str;
   Dollarsign:=pos(denominator,Tempstr);
   if dollarsign<>0 then Delete(Tempstr,dollarsign,1);
   Comma:=Pos(Delimiter,tempstr);
   if Comma<>0 then delete (Tempstr,comma,1);
   Result:=strToCurr(Tempstr);
end;



And just use FormatStr to get it all back.


Good luck!!



0
 
LVL 4

Author Comment

by:Greg Rowland
ID: 6954875
Copy that Doc!

There must be away to pass/convert a string like '$1,569.34' to
Fields[i].SomeThing := String; where fields[i] is a currency or float type.

Without having to preprocess the string to meet ‘1569.34’ first.

It just seems goofy that StrToCurr('$1,569.34') can’t handle this, it is after all pretty obviously a currency string!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:DrDelphi
ID: 6958478
Well, I suppose you could derive a new descendant class from TField and add a .AsMoney method to it... of course you'd have to put that into a string field (or blob, etc)... chances are that the table isn't going to like it otherwise.


Good luck!!
0
 
LVL 4

Author Comment

by:Greg Rowland
ID: 6980930
Thanx Doc,

Your code my style, works great, still can't believe this is not built into the language.

// Remove $ and , from currency strings --------- 1:00 PM 4/19/2002gr
function myStrToCurrEX( s: String): String;
var
   d, c: Integer;

begin
  // String Contains '$' Sign?
  d := pos( '$', s);
  if (d <> 0) then
    Delete( s, d, 1);

  // String Contains ',' Sign?
  c := Pos( ',', s);
  if (c <> 0) then
    Delete( s, c, 1);

    RESULT := s;

end;
0
 
LVL 6

Expert Comment

by:DrDelphi
ID: 6980998
Cheers!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question