473,378 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Currency class

Java has this. Anyone know of a .Net equivalent?

Thanks,
Eric
Nov 30 '06 #1
5 8259
Eric wrote:
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 Porterfield

Nov 30 '06 #2
Tom Porterfield wrote:
Eric wrote:
>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).
The currency code is available in the RegionInfo class.

RegionInfo ri = new RegionInfo(CultureInfo.CurrentCulture.LCID);
string currencyCode = ri.ISOCurrencySymbol;
--
Tom Porterfield

Nov 30 '06 #3
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
"Tom Porterfield" <tp******@mvps.orgwrote in message
news:eX****************@TK2MSFTNGP02.phx.gbl...
Tom Porterfield wrote:
>Eric wrote:
>>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).

The currency code is available in the RegionInfo class.

RegionInfo ri = new RegionInfo(CultureInfo.CurrentCulture.LCID);
string currencyCode = ri.ISOCurrencySymbol;
--
Tom Porterfield

Dec 1 '06 #4
On Thu, 30 Nov 2006 19:32:36 -0800, Eric wrote:
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.
--
Tom Porterfield
Dec 1 '06 #5
Thanks Tom - that is pretty much what did the trick

"Tom Porterfield" <tp******@mvps.orgwrote in message
news:gu**************@tpportermvps.org...
On Thu, 30 Nov 2006 19:32:36 -0800, Eric wrote:
>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.
--
Tom Porterfield

Dec 2 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dennis | last post by:
I'm trying to output currency columns to the console in table format. I need a class that allows me to format doubles to currency and have the columns right-justified. I've come up with a...
2
by: Willing 2 Learn | last post by:
I'm still having trouble getting my program to do arithmetic in cents(keeping all #'s) then convert the answer in a format of dollars & cents. The main program should add, subtract, scalar...
2
by: Paul Wistrand | last post by:
Hi, does anyone know if there are any opensource implemenations of an Currency class for the .NET framework?
2
by: C CORDON | last post by:
I am creating a windows Class library Project, but it won't let me declare any var as Currency! Why is this? TIA! :)
1
by: Doug Bell | last post by:
Hi, Hi had a DataGrid on a form and was using the CurrentCellChanged Event to determine the selected row: Private Sub grdSelOrd_CurrentCellChanged(ByVal sender As System.Object, _ ByVal e As...
5
by: Theodore | last post by:
Hi, i have a class "MyClass" with a public property of datatable type. I also have a form with a public property of type "MyClass". The form has a datagrid which binds to MyClass.Table datatable....
2
by: Octavio Hernandez | last post by:
Hi, I have a seemingly easy problem drivin' me nuts. I'd be grateful for any hint on what may be causing it. The fact is I'm developing an ASP.NET web site. At some point, I need to read a...
18
by: Boris Yeltsin | last post by:
OK, I have a database table, it has prices of products in it, like so: ProductPrice MONEY ProductIsoCurrencyCode CHAR(3) Now, both CultureInfo and RegionInfo have...
3
by: Eric | last post by:
I know this is a property of the RegionInfo class. I figure somewhere in the framework is the actual enumeration, which I would like to use. I want to use it to support a Money class I need,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.