Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Format currency to string

Posted on 2000-04-24
9
Medium Priority
?
2,102 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 75 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
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.

 
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 October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

618 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