Solved

# Format currency to string

Posted on 2000-04-24
Medium Priority
2,032 Views
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
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
• 3
• 3
• 2
• +1

LVL 3

Expert Comment

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

LVL 1

Accepted Solution

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

ID: 2744238
Sorry Shengw,

When I started your comment was not up

Regards
Asw
0

LVL 3

Expert Comment

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

Expert Comment

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

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

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

ID: 2746646
Hi Softtech,

Try this

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

Asw
0

Author Comment

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

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small printâ€¦
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy reâ€¦
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to fâ€¦
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrasâ€¦
###### Suggested Courses
Course of the Month9 days, 17 hours left to enroll