Help Needed with a little .Net function...
secretGeek .:dot Nuts about dot Net:.
home .: about .: sign up .: sitemap .: secretGeek RSS

Help Needed with a little .Net function...

 

        /// <summary>

        ///Given an 'ISO 4217' three letter code for a currency...

        ///Return the 'CurrencySymbol' that represents it

        /// </summary>

        /// <param name="ISOCurrency">3 letter ISO427 currency code, e.g. "USD", "GBP", "EUR", "AUD"</param>

        /// <returns>Currency Symbol, e.g. "$", "£", "€", "$"</returns>

        public string GetCurrencySymbol(string ISOCurrency)

        {

            return "HELP ME!";

        }





'Daniel' on Mon, 12 Dec 2005 03:02:48 GMT, sez:

Would something like work?:

public string GetCurrencySymbol(string ISOCurrency)

{

RegionInfo ri = new RegionInfo(ISOCurrency)
return ri.ISOCurrencySymbol;
}



'leon' on Mon, 12 Dec 2005 03:38:37 GMT, sez:

no sorry daniel -- not quite right.

the constructor to RegionInfo takes a two-letter Region code, such as "IT" for italy.

What i want to send in is a currency indicator, such as "EUR" for Euro.

The last line could instead be
"return ri.CurrencySymbol;"



'Daniel' on Mon, 12 Dec 2005 03:51:37 GMT, sez:

Sorry I should have expanded, I was meaning could you change your requirements to fit the RegionInfo class?



'leon' on Mon, 12 Dec 2005 04:00:24 GMT, sez:

"could you change your requirements to fit "

I like the way you think Daniel -- though i'd rather not change the requirements.

in any case -- it's great to be visited by a Brisbaner!



'hardbutnot' on Mon, 12 Dec 2005 09:05:49 GMT, sez:

As always, first choice solution = google for it, <strike>steal</strike> borrow/pay for it...

http://www.freedownloadmanager.org/downloads/Country_Codes_28720_p/

a free database of country - currency - lots of other rubbish. yay.

but. Then I think that if it was me I'd use the function detailed by Daniel previously and add a Currency to Country convertion bit before calling the "return ri.CurrencySymbol;" line.

So then I went googling for Currency to Country and found the following on MSDN...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/pjsdk/html/pjprocurrencysymbol_HV45317832.asp

-----------8<----------
Select Case Country
Case "US", "United States", "USA", "United States of America"
ActiveProject.CurrencySymbol = "$"
ActiveProject.CurrencySymbolPosition = pjBefore
Case "ENGLAND"
ActiveProject.CurrencySymbol = Chr(163)
ActiveProject.CurrencySymbolPosition = pjBefore
Case "SWEDEN"
ActiveProject.CurrencySymbol = "kr"
ActiveProject.CurrencySymbolPosition = pjAfterWithSpace
' Warn user if the currency format is not known.
Case Else
MsgBox ("The currency format for that country is unknown.")
End Select

-----------8<----------

which made me laugh. Three ways to specify USA, ENGLAND (not britain or uk or scotland or wales or ireland or ...) and SWEDEN listed as if they are the only other two countries in the world. Else *Unknown*.

So I suggest copying this logic (if it's good enough for MS...)

public string GetCurrencySymbol(string ISOCurrency) {
if (ISOCurrency == 'USD') return '$';
elseif (ISOCurrency == 'GBP') return '£';
elseif (ISOCurrency == 'SEK') return 'K';
else return '';
}

and final solution -- do some javascript to pull the information from this page !

http://www.xe.com/iso4217.htm



'Omer van Kloeten' on Mon, 12 Dec 2005 16:27:49 GMT, sez:

  //Don't forget: 'using System.Globalization;'

   

  private static Hashtable currencySymbols;

   

  /// <summary>

  /// Given an 'ISO 4217' three letter code for a currency...

  /// Return the 'CurrencySymbol' that represents it

  /// </summary>

  /// <param name="ISOCurrency">3 letter ISO427 currency code, e.g. 'USD', 'GBP', 'EUR', 'AUD'</param>

  /// <returns>Currency Symbol, e.g. '$', '£', '€', '$'</returns>

  public static string GetCurrencySymbol(string ISOCurrency)

  {

      if (currencySymbols == null)

   

      {

          currencySymbols = new Hashtable();

   

              foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures))

   

              {

                  RegionInfo ri = new RegionInfo(ci.LCID);

   

                  if(!currencySymbols.ContainsKey(ri.ISOCurrencySymbol))

                      currencySymbols.Add(ri.ISOCurrencySymbol, ri.CurrencySymbol);

              }

      }

   

      return currencySymbols[ISOCurrency].ToString();

  }


I think it's the only way. Ugly, but I think it's the only way.
Also, consider making the method static. It's not really an instance action, IMHO.



'leon' on Mon, 12 Dec 2005 20:26:05 GMT, sez:

Thanks Omer!

Brilliant solution.

(i re-formatted it as html, using the "Copy as Html" add in for Visual Studio)

Anyway: I'm not going to use it... because on closer inspection what the client would like is if we don't use a currency symbol at all for foreign currencies -- just include a label that says "All prices are in GBP"...



'=8)-DX' on Fri, 09 Jun 2006 21:18:50 GMT, sez:

I've just been working on this problem - it is much simpler, Daniel almost got it. The catch is that the first two letters of the ISO 4217 Currency codes are the region (Ie US in USD)

public string GetCurrencySymbol(string ISOCurrency)
{
string ISORegion = ISOCurrency.SubString(0,2)
RegionInfo ri = new RegionInfo(ISORegion)
return ri.ISOCurrencySymbol;
}




name


website (optional)


enter the word:
 

comment (HTML not allowed)


All viewpoints welcome. But the right to delete any post for any reason is reserved. Don't make me do it. Aim for constructiveness. Comments may be republished, emailed to your loved ones or printed and used as toilet paper. Also, I get particularly nasty on comment spam. It's not worth even trying to post comment spam here -- your html is escaped, and your links are given a rel='nofollow'. By attempting to post a comment, you understand that if the comment is considered spam, at my absolute discretion, your IP address may be used as the target of a prolonged distributed denial of service attack. Your electricity might suddenly stop working. Your car tyres will go mysteriously flat. You will suffer permanent hairloss. Your dreams will be filled with terrifying monsters. And in any case I reserve the right to record and publish your IP address.

 

TimeSnapper is a life analysis system that stores and plays-back your computer use. It makes timesheet recording a breeze, helps you recover lost work and shows you how to sharpen your act.

 

NimbleText - FREE text manipulation and data extraction

NimbleText is a Powerful FREE Tool

Use it for:

  • extracting data from text
  • manipulating text
  • generating code

It makes you look awesome. Use it right now! Go on! Hurry! Don't walk, run!

 

Articles

Just Wally Just Wally
The Correct Order for a First Time Viewing of The Lord Of The Rings The Correct Order for a First Time Viewing of The Lord Of The Rings
A new era for Android. A new era for Android.
Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion
Got CSV in your javascript? Use agnes. Got CSV in your javascript? Use agnes.

Archives Complete secretGeek Archives

TimeSnapper -- Automated Screenshot Journal TimeSnapper: automatic screenshot journal
NimbleText -- World's Simplest Code Generator NimbleText: Code Generator, Text Manipulator, Data Extractor

25 steps for building a Micro-ISV 25 steps for building a Micro-ISV
3 minute guides -- babysteps in new technologies: powershell, JSON, watir, F# 3 Minute Guide Series
Universal Troubleshooting checklist Universal Troubleshooting Checklist
Top 10 SecretGeek articles Top 10 SecretGeek articles
ShinyPower (help with Powershell) ShinyPower
Now at CodePlex

Realtime CSS Editor, in a browser RealTime Online CSS Editor
Gradient Maker -- a tool for making background images that blend from one colour to another. Forget photoshop, this is the bomb. Gradient Maker


[powered by Google] 


How to be depressed How to be depressed
You are not inadequate.



Recommended Reading


the little schemer


The Best Software Writing I
The Business Of Software (Eric Sink)

Recommended blogs

Jeff Atwood
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Rhys Parry
Joel Pobar
Thomas White
OJ Reeves
Eric Sink

Aggregated Links

proggit
dzone
hacker news
dot net kicks

Human Link Machines

interesting finds
a continuous learner's weblog
arjan's world
weekly link post

LinkedIn profile
LogEnvy - event logs made sexy
Computer, Unlocked. A rapid computer customization resource
PhysioTec, Brisbane Specialist Physiotherapy & Pilates
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2003 .: privacy

home .: about .: sign up .: sitemap .: RSS .: © Leon Bambrick 2003 .: privacy