Solved

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

Posted on 2002-04-19
6
649 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 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: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

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month3 days, 19 hours left to enroll

630 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