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

VBScript FormatCurrency - how to change the currency symbol

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

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 50

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP Sessions Being Cleared/Modified 6 87
Forcing form refresh - classic ASP 7 72
Need help to rewrite script 3 94
IP API - need data... 4 27
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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

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