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
Solved

Format currency to string

Posted on 2000-04-24
9
1,854 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Dbf export problem to a Visual Foxpro application 6 207
code issue 8 153
oracle global variables 4 76
can't find the executable in Simulator 1 100
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

839 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