To implement a currency converter for helping the buyers to know how much cost in their own currency?
In my asp.net(c#) shopping cart web application.
I need to implement a currency converter for helping the buyers to know how much cost in their own currency.
When a开发者_如何学运维 buyer selects his country.I need to show the converted amount based on his country. Please give examples/reference links for solving the same.
You can use a web service like http://webservices.lb.lt/ExchangeRates/ExchangeRates.asmx to get the currency rates and calculate the details in your application.
Be careful state that the rates are indicative and might be different in billed charges.
It's a pretty big topic, and there are lots of factors to consider. Rates are likely to be different in different countries, and buying and selling rates also varies. Most credit card companies also use "secret" exchange rate when you make a purchase in a another currency. Add to that various fees...
In Denmark, the Danish National Bank publish the official rate on their website in xml format. It's pretty easy to read this file, and create a simple converter. And I would suspect you could find similar services offered around the world from national banks, credit card companies or other service providers.
On a side note: Did you know Google can do currency exchange rates too? Try googling "100 EUR in USD" and see what you get... :)
Implementation
Every user has a session object you can use. When the user changes the country in the dropdown you can use the automatic postback functionality of the dropdown and fire the selectedindexchanged event. Within the eventhandler you save the country id in the session. Now you can work with that country throughout your whole application.
Now everywhere you work with a currency you have to use a kind of converter that uses the country and the according rate. Something like (this is just an example, not useable code):
decimal price = 10.95; lblPrice.Text = price * ((Country)Session["country"]).Rate;
Currency rates
The most easiest way, and better for the performance, is saving the rates in the database and update them once in a while. This is a whole other solutions which can have a ton of different implementations.
精彩评论