Solved

VBScript FormatCurrency - how to change the currency symbol

Posted on 2016-08-19
4
32 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

706 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

21 Experts available now in Live!

Get 1:1 Help Now