Currency class

  • Thread starter Thread starter Eric
  • Start date Start date
Eric said:
Java has this. Anyone know of a .Net equivalent?

What part of Currency do you need? Using a NumberFormatInfo object along
with the culture of choice will get you some of the functionality. Here is
an example of some of the values available:

NumberFormatInfo nf = CultureInfo.CurrentCulture.NumberFormat;
int fractionDigits = nf.CurrencyDecimalDigits;
string symbol = nf.CurrencySymbol;
string groupSeparator = nf.CurrencyGroupSeparator;
string decimalSeparator = nf.CurrencyDecimalSeparator;

I don't believe there is anything in .NET that will give you the currency
code.

Create a CultureInfo object for the culture of your choice if you want one
other than the current culture (ex: CultureInfo ci = new
CultureInfo("en-GB");). You can use the NumberFormatInfo object in calls to
Parse and Format methods on your numeric objects (int, decimal, double,
etc).
 
Tom said:
What part of Currency do you need? Using a NumberFormatInfo object along
with the culture of choice will get you some of the functionality. Here
is an example of some of the values available:

NumberFormatInfo nf = CultureInfo.CurrentCulture.NumberFormat;
int fractionDigits = nf.CurrencyDecimalDigits;
string symbol = nf.CurrencySymbol;
string groupSeparator = nf.CurrencyGroupSeparator;
string decimalSeparator = nf.CurrencyDecimalSeparator;

I don't believe there is anything in .NET that will give you the currency
code.

Create a CultureInfo object for the culture of your choice if you want one
other than the current culture (ex: CultureInfo ci = new
CultureInfo("en-GB");). You can use the NumberFormatInfo object in calls
to Parse and Format methods on your numeric objects (int, decimal, double,
etc).

The currency code is available in the RegionInfo class.

RegionInfo ri = new RegionInfo(CultureInfo.CurrentCulture.LCID);
string currencyCode = ri.ISOCurrencySymbol;
 
It really is the currency code I'm after - I want to build a Money class
along the lines of Fowler's pattern. So what I would ideally like is an
enumeration of all the currency codes net knows about, anyone of which could
be an attribute of a given Money instance.

I found the RegionInfo.IsoCurrencyCode property, but couldn't figure out how
to get an enumeration out of it. If we had a class like Java's Currency I'd
have enough of the values and type safety I'm looking for.

Thanks,
Eric
 
It really is the currency code I'm after - I want to build a Money class
along the lines of Fowler's pattern. So what I would ideally like is an
enumeration of all the currency codes net knows about, anyone of which could
be an attribute of a given Money instance.

I found the RegionInfo.IsoCurrencyCode property, but couldn't figure out how
to get an enumeration out of it. If we had a class like Java's Currency I'd
have enough of the values and type safety I'm looking for.

It would be tough, and not like java. You can get all the cultures by
accessing CultureInfo[] CultureInfo.GetCultures(). You would then need to
build a RegionInfo object from each CultureInfo in the array and then get
the ISOCurrencySymbol.
 
Thanks Tom - that is pretty much what did the trick

Tom Porterfield said:
It really is the currency code I'm after - I want to build a Money class
along the lines of Fowler's pattern. So what I would ideally like is an
enumeration of all the currency codes net knows about, anyone of which
could
be an attribute of a given Money instance.

I found the RegionInfo.IsoCurrencyCode property, but couldn't figure out
how
to get an enumeration out of it. If we had a class like Java's Currency
I'd
have enough of the values and type safety I'm looking for.

It would be tough, and not like java. You can get all the cultures by
accessing CultureInfo[] CultureInfo.GetCultures(). You would then need to
build a RegionInfo object from each CultureInfo in the array and then get
the ISOCurrencySymbol.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top