Solved

Format currency to string

Posted on 2000-04-24
9
1,960 Views
Last Modified: 2010-04-04
Assuming...

var
  Money : Currency;

How does one convert a TCurrency value to a formatted string, such as...

$x,xxx,xxx.xx

...so that if Money := 1234.5 then the resulting text string would contain '$1,234.50'
0
Comment
Question by:Softtech
[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
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 3

Expert Comment

by:shenqw
ID: 2744152
procedure TForm1.Button1Click(Sender: TObject);
begin
  CurrencyString:='$';
  CurrencyFormat:=0;
  ThousandSeparator:=',';
  ShowMessage(Format('%.2m',[12345.5]));
end;
0
 
LVL 1

Accepted Solution

by:
Asw earned 25 total points
ID: 2744174
procedure TForm1.Button1Click(Sender: TObject);
Var
Money : Currency;
begin
Money := 1234.50;
Label1.Caption := FloatToStrF(Money, ffCurrency, 4, 2);
end;

Asw
0
 
LVL 1

Expert Comment

by:Asw
ID: 2744238
Sorry Shengw,

When I started your comment was not up

Regards
Asw
0
Independent Software Vendors: 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 3

Expert Comment

by:shenqw
ID: 2744325
My name is shenqw,but many many people ask me shengw.Oh,my god!  ^o^
0
 

Expert Comment

by:Aleq
ID: 2744561
Hi. You can use delphi CurrToStr, that converts currency according to windows language settings.

function CurrToStr(Value: Currency): string;
from SysUtils unit;

Shenqw: I have the very same problem - they call me Aleg although I'm AleQ
0
 

Author Comment

by:Softtech
ID: 2745186
The precision "4" is insufficient for a value such as 1234.50, nonetheless ASW's response comes closest to meeting my needs.

Thank you Shenq, however, the '[1234.50]' did not fulfil my needs, since I was trying to pass a variable, not a static value.
0
 
LVL 3

Expert Comment

by:shenqw
ID: 2745906
oh,my god!!!

why you not try:

procedure TForm1.Button1Click(Sender: TObject);
var
  Money : Currency;
begin
  Money:=12345.5;
  CurrencyString:='$';
  CurrencyFormat:=0;
  ThousandSeparator:=',';
  ShowMessage(Format('%.2m',[Money]));
end;

0
 
LVL 1

Expert Comment

by:Asw
ID: 2746646
Hi Softtech,

Try this

Var
Money : Currency;
begin
Money := 1234.50;
Label1.Caption := FloatToStrF(Money, ffCurrency, 6, 2);

Asw
0
 

Author Comment

by:Softtech
ID: 2753791
Shenqw asked: oh,my god!!! why you not try:

My reply:  Why?  Because I'm a novice and you are the expert, and your original response assumed I knew that the variable 'Money' could be placed between [] brackets...which I did not know.
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

690 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