Solved

TField.AsCurrency - How use a different currency symbol than $ ?

Posted on 2007-11-20
5
715 Views
Last Modified: 2012-06-27
Hello,

I'm trying to use TField.AsCurrency, but I want to display an amount in euros, not dollars?  How can I make it use a different currency symbol?  Here's what I have so far:

          Value := dataModule.tblOutput.FieldByName('ExtendedList').AsCurrency;

This always gives me '$100.00' or the like.  I need it just show the amount in euros, or a secondary goal would be to display the number in currency format (2 decimal places) without the currency symbol at all.

Thanks!
0
Comment
Question by:light_bulb
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 20319957
use the global variable CurrencyString  to the desired value.
0
 
LVL 13

Expert Comment

by:rfwoolf
ID: 20320012
When working with currency I believe by default it uses your locale settings, set:
Control Panel -> Regional and Language Options

***TRY*** this, might work, not sure where it should go, try in your application's main form, else your Project -> View Source.
CurrencyString := 'R$';
0
 
LVL 28

Accepted Solution

by:
2266180 earned 500 total points
ID: 20320466
getting over the fact that I suggested the use of currencystring before you.

R$ ??? lol. what's that for?
R$ will only make the string look like: R$100.00
which in my opinion is not helping.

he either wants to use
CurrencyString := '';
or
CurrencyString := 'euro';

also setting the CurrencyFormat and NegCurrFormat      might be desirable

CurrencyDecimals needs to be set for teh number of digits after the dot

and as I understood, this is about a value displayed in a table or using currtostr fucntion

if it's the latter then I suggest soemthing like this:

var value:currency;
    fs:tformatsettings;
begin
  GetLocaleFormatSettings(LOCALE_SYSTEM_DEFAULT, fs);
  fs.CurrencyString:='euro';
  fs.CurrencyFormat:=3;
  Value := dataModule.tblOutput.FieldByName('ExtendedList').AsCurrency;
  showmessage(CurrToStrF(value, ffCurrency, 2, fs));// this is placed wherever the string needs to be put

if no currency string is needed then use
  fs.CurrencyString:='';
  fs.CurrencyFormat:=0;

everything that is in tformatsettings is also as a global variable, so if you need this in the default TDBTable, then you need to set the global variable (that's why I suggested it in the first place).

the global vairables are not thread safe whereas the formatsettings variable approach is thread safe. that woul dbe the main difference between the 2 approaches.
0
 
LVL 13

Expert Comment

by:rfwoolf
ID: 20320509
Your reaction is not entirely appropriate, it's what they call an "Edit conflict" -- when I posted my solution you had beat me to it - doesn't mean I maliciously copied your solution in an attempt to, well, I don't know.

Secondly, you are correct about R$ but this would have worked anyway. The solution I had looked up used that symbol, so that's what I had copy-pasted in a hurry -- not in a hurry enough I might add since you had already pasted an answer.

You need not fear, you got awarded the points anyway. The OP can see you posted it first.
0
 
LVL 28

Expert Comment

by:2266180
ID: 20320790
I've been around for a few years and I've seen too many answers accepted by the question askers where the accepted answer was a "better"/"more details"/"had an example"/etc answer. (and I don't exagerate when I say too many)
it's like I don't have the time to post an example, or just am in a hurry or whatever and somebody comes along and based on my suggestion, makes  a small demo and they get the points (all of them. been there, seen that, again too many times).
and a few times, the question asker admitted they didn't look attentivly to my answer because it did not contain an example of usage.

bleah. anyway, I now have some "weird" policies towards what and how I ask on EE, my "reaction" was just one of those. I don't care about the points. if you look closely, I've got plenty of them. But I do care that if I give a correct answer, I get what is fairly mine. and that is in almost all cases the grade :) this case could have been a points split for all I care, but I have bigger problems than points, and that is askers that don't know/care how to grade.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

867 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