Currency Symbols

  • Thread starter Thread starter David C
  • Start date Start date
D

David C

I have a need to display amounts from an import file in a GridView column
with different currency symbols based on what country the amount is from. I
looked at the formatting but could not figure out how to do this. It would
be nice to simply set the currency symbol in RowDataBound event. Can anyone
help with this? Thanks.

David
 
I have a need to display amounts from an import file in a GridView column
with different currency symbols based on what country the amount is from. I
looked at the formatting but could not figure out how to do this. It would
be nice to simply set the currency symbol in RowDataBound event.  Can anyone
help with this?  Thanks.

David

You can easily do this if you know the culture name. For example, en-
US for US, sv-SE for Sweden...

Then

double v = 1234.567d;
System.Globalization.CultureInfo c = new
System.Globalization.CultureInfo("sv-SE");
Response.Write(v.ToString("C", c));

would give you a string with a currency symbol.
 
I have a need to display amounts from an import file in a GridView column
with different currency symbols based on what country the amount is from.
I
looked at the formatting but could not figure out how to do this. It would
be nice to simply set the currency symbol in RowDataBound event. Can
anyone
help with this? Thanks.

David

You can easily do this if you know the culture name. For example, en-
US for US, sv-SE for Sweden...

Then

double v = 1234.567d;
System.Globalization.CultureInfo c = new
System.Globalization.CultureInfo("sv-SE");
Response.Write(v.ToString("C", c));

would give you a string with a currency symbol.

Thank you both. It worked like a charm!

David
 
I have a need to display amounts from an import file in a GridView
column with different currency symbols based on what country the
amount is from. I looked at the formatting but could not figure out
how to do this. It would be nice to simply set the currency symbol in
RowDataBound event. Can anyone help with this? Thanks.

Everyone is leading you to globalization/localization, which is fine if
the issue is displaying in the user's currency. You simply output
ToString("C") and make sure you have the web app set to respect the
currency of the user's settings. This does not sound like your issue,
but if it is, there are plenty of sites showing how to set currency to
the user's specifics. Converting to the currency requires knowing the
conversion rates.

It sounds like you mean the actual transaction was in a certain
currency, which is a slight different issue. In this case, you can still
use ToString("C"), but you will have to set the culture of the thread
programatically to get er done. And you will want to set the culture of
the worker thread for the request back to the normal culture after you
do this.

The other option is to set up your own library to return the currency
with the correct symbol or look for a third party library.

Of the options, temporarily flipping the thread to the culture of the
currency and then back will be the least amount of work up front. To
make this easiest, you need a culture lookup (table if it were me) that
can link to whatever indicator you use in the database to identify the
currency or country of the transaction.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 

I love the "let me google that for you", but I think the OP needs advice
on setting individual rows based on the country the transaction was
from, not the country of the user. Same advice, if you are willing to
flip the thread and then flip back on binding complete, but it is a
different problem domain from "why are my user's in Mexico not seeing
pesos".

peace and grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Gregory A. Beamer said:
Everyone is leading you to globalization/localization, which is fine if
the issue is displaying in the user's currency. You simply output
ToString("C") and make sure you have the web app set to respect the
currency of the user's settings. This does not sound like your issue,
but if it is, there are plenty of sites showing how to set currency to
the user's specifics. Converting to the currency requires knowing the
conversion rates.

It sounds like you mean the actual transaction was in a certain
currency, which is a slight different issue. In this case, you can still
use ToString("C"), but you will have to set the culture of the thread
programatically to get er done. And you will want to set the culture of
the worker thread for the request back to the normal culture after you
do this.

The other option is to set up your own library to return the currency
with the correct symbol or look for a third party library.

Of the options, temporarily flipping the thread to the culture of the
currency and then back will be the least amount of work up front. To
make this easiest, you need a culture lookup (table if it were me) that
can link to whatever indicator you use in the database to identify the
currency or country of the transaction.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************

We are actually getting a feed from a separate system. That system has an
amount field (CSV file) and will also have a "Currency Code" for us to
display (have not seen it yet) and I am guessing it to have codes like "US",
"FR", "CA", etc. Our users want to see the representation of that amount
using appropriate currency symbols. We do not need to convert anything,
e.g. dollars to franks, etc., just show the symbol. Then we need to toal by
each "Currency Code".

Thus, your solution is fine.

David
 
Gregory A. Beamer said:
Everyone is leading you to globalization/localization, which is fine if
the issue is displaying in the user's currency. You simply output
ToString("C") and make sure you have the web app set to respect the
currency of the user's settings. This does not sound like your issue,
but if it is, there are plenty of sites showing how to set currency to
the user's specifics. Converting to the currency requires knowing the
conversion rates.

It sounds like you mean the actual transaction was in a certain
currency, which is a slight different issue. In this case, you can still
use ToString("C"), but you will have to set the culture of the thread
programatically to get er done. And you will want to set the culture of
the worker thread for the request back to the normal culture after you
do this.

The other option is to set up your own library to return the currency
with the correct symbol or look for a third party library.

Of the options, temporarily flipping the thread to the culture of the
currency and then back will be the least amount of work up front. To
make this easiest, you need a culture lookup (table if it were me) that
can link to whatever indicator you use in the database to identify the
currency or country of the transaction.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************

p.s. I would put the codes in a table also.
 
p.s. I would put the codes in a table also.- Hide quoted text -

If your application is used for many countries, it really does make
sense. There are few cases when some countries officially use more
than one currency, or changing local currency from one to another
(e.g. in Europe, new countries such as Estonia and Lithuania would get
EUR in 2010). Keeping currency in the database would answer all
questions and makes your life easier ;-)
 
We are actually getting a feed from a separate system. That system
has an amount field (CSV file) and will also have a "Currency Code"
for us to display (have not seen it yet) and I am guessing it to have
codes like "US", "FR", "CA", etc. Our users want to see the
representation of that amount using appropriate currency symbols. We
do not need to convert anything, e.g. dollars to franks, etc., just
show the symbol. Then we need to toal by each "Currency Code".

Thus, your solution is fine.

The big thing is flipping the thread back if there are additional bits
on the page that need the user's thread. if not, just flip the thread to
other cultures and "print out" as currency.

Good to hear this will work for you.

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top