Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2002-04-19
6
Medium Priority
?
671 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

670 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