Solved

Format currency to string

Posted on 2000-04-24
9
1,796 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
  • 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
 
LVL 3

Expert Comment

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

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

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

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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

14 Experts available now in Live!

Get 1:1 Help Now