Solved

VBScript FormatCurrency - how to change the currency symbol

Posted on 2016-08-19
4
75 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
[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
  • Learn & ask questions
  • 2
4 Comments
 
LVL 52

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 52

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 18

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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/…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

615 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