Solved

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

Posted on 2002-04-19
6
625 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:SurferJoe
  • 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 25 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:SurferJoe
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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:SurferJoe
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can't connect to Outlook via TOutlookApplication component 15 118
code issue 8 99
Using idhttp to login to instagram 2 76
Tembedded WB animatid gifs not animated on some pcs 2 72
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now