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. Comments may be republished, emailed to your loved ones or printed and used as toilet paper. Who reads this legal bit anyhow?

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.

TimeSnapper won last year's Developer Competition at Larkware.com, and is used by over 10,000 people.

Articles

TimeSnapper 3.2: What are you afraid of? TimeSnapper 3.2: What are you afraid of?
Babbage and Boole! Babbage and Boole!
Downloadable Slide-decks: Downloadable Slide-decks: "Build your own Tiny Software Company"/"F# eye for the C# guy"
Simple Trouble Shooting Application Now Fixes Everything Simple Trouble Shooting Application Now Fixes Everything
a simple checklist for trouble-shooting regular problems a simple checklist for trouble-shooting regular problems
secretGeek at Tech-Ed: secretGeek at Tech-Ed: "How to build your own Tiny Software Company"
Bambrick versus Hanselman: Bring it! Bambrick versus Hanselman: Bring it!

Archives .: secretGeek :: Complete Archives :.
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
Top 10 SecretGeek articles Top 10 SecretGeek articles

Downloads

TimeSnapper -- Automated Screenshot Journal TimeSnapper.com    
Version 3.1: instant productivity profiles

ShinyPower (help with Powershell) ShinyPower
Now at CodePlex

Next Action NextAction
Managing the top of your mind



[powered by Google] 


World's Simplest Code Generator (html edition) World's Simplest Code Generator
Gradient Maker -- a tool for making background images that blend from one colour to another. Forget photoshop, this is the bomb. Gradient Maker
How to be depressed How to be depressed
You are not inadequate.



Recommended Reading

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

Recommended blogs

Jeff Atwood
Reginald Braithwaite
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Joel Pobar
Eric Sink
Joel Spolsky
Des Traynor

Aggregated Links

programming.reddit.com
dzone
dot net kicks

Human Link Machines

interesting finds
a continuous learner's weblog
arjan's world
n links today
new and notable
morning coffee
learning .net
weekly link post
(my del.icio.us account)

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

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