Solved

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

Posted on 2002-04-19
6
621 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 6

Expert Comment

by:DrDelphi
Comment Utility
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
Comment Utility
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
Comment Utility
Cheers!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

8 Experts available now in Live!

Get 1:1 Help Now