Solved

VBScript FormatCurrency - how to change the currency symbol

Posted on 2016-08-19
4
39 Views
Last Modified: 2016-08-29
Hi all, just curious is anyone knows how to change the currency symbol from $ (Dollar) to Euro or Pound, etc?
0
Comment
Question by:Graeme
  • 2
4 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 41762156
try use FormatNumber function instead, and add in your own currency symbol when necessary.

http://www.w3schools.com/asp/func_formatnumber.asp
0
 
LVL 49

Assisted Solution

by:Ryan Chong
Ryan Chong earned 500 total points
ID: 41762157
or you got to do a Replace for the currency symbol from FormatCurrency function.
0
 
LVL 17

Expert Comment

by:xtermie
ID: 41762170
You can use the VBScript SetLocale function in conjunction with FormatCurrency to change the currency symbol displayed.

SetLocale(LCID)
You can use the Decimal, Hex, or Short String value for the LCID (Locale ID), for example these will all set the Locale to English - United Kingdom:

SetLocale("en-gb")   :    SetLocale(0x0809)    :    SetLocale(2057)

You can find a list of all the LocaleID's in the Windows Script Documentation.


SetLocale example code

<%
dblPrice = 123.456
If IsNumeric(dblPrice) Then
   intLocale = SetLocale(2057)                 ' English - United Kingdom - £
   curPounds = FormatCurrency(dblPrice, 2)     ' curPounds contains £123.46
   intLocale = SetLocale(1033)                 ' English - United States
   curDollars = FormatCurrency(dblPrice, 2)    ' curDollars contains $123.46
   intLocale = SetLocale(1036)                 ' French - France
   curFrancs = FormatCurrency(dblPrice, 2)     ' curFrancs contains 123.46 F
End If
%>


In regards to the euro, one might expect that using the SetLocale function to set the LocaleID to that of country which now uses the Euro, France, Germany Spain etc. in conjunction with the FormatCurrency function would produce the result in Euros: 123,45 €

However, this isn't always the case, using this method the Euro symbol will only be displayed if the host server is Windows XP or Server 2003. If the server is Windows 2000 the country's pre-Euro currency symbol may be used. Therefore this method can not be relied upon in all cases.

However, we can work around this by manually adding the Euro symbol, purely for display purposes, for example:

<%
dblPrice = 123.456
If IsNumeric(dblPrice) Then
   intLocale = SetLocale(2057)                   ' English - United Kingdom - £
   curPounds = FormatCurrency(dblPrice, 2)       ' curPounds contains £123.46
   intLocale = SetLocale(1033)                   ' English - United States
   curDollars = FormatCurrency(dblPrice, 2)      ' curDollars contains $123.46
   intLocale = SetLocale(1033)                   ' English - United States
   curEuros = FormatNumber(dblPrice, 2) & " €"   ' curEuros contains 123,46 €
End If
%>

NOTE: I have still used the SetLocale function, prior to FormatNumber in order to display the numbers in the national preference for France where a comma is used to indicate the decimal point: 123,46 €
0
 

Author Closing Comment

by:Graeme
ID: 41774665
After looking through alot of very complex options, I think this simple one is the best
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

Suggested Solutions

Title # Comments Views Activity
Migrated SQL connection issues 2012 6 39
IIS POST request being ignored 4 53
toggle checkboxes when a checkbox is checked 16 51
replace quotes with UTF-8 character 38 82
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

932 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

9 Experts available now in Live!

Get 1:1 Help Now