Saturday, July 05, 2008 10:29 AM
Michael S. Kaplan
Show me the money? How?
Regular reader Jan Kučera's latest attempt to thwart my fantasy of emptying the Suggestion Box went something like this:
Hello again,
I'm trying to display prices, in a currency the user chooses. I've abolised keeping my own formatting info for each currency, and decided to assign a culture to the currency, and let the .NET to format the price using its data (I hope this is a good decision :)), so the list of available currencies is like USD -> en-US, GBP -> en-GB etc.
Now the question, what culture should I choose to format the price in euros? Are the formatting rules the same for whole union and I can just randomly choose one country?
Or is there any IFormatProvider for whole EU?
Thanks!
Jan
PS. Well by checking all cultures which has € as a currency symbol I see that every country formats the currency in a different way, so this is not going to work. So is the suggested way to use the USD/GBP strings and format the price as a number using user's culture?
It is funny that the question of formatting is so prominent here -- isn't the big problem the actual conversion? The formatting seems like the easiest issue....
As I mentioned in Show me the [small]money!, I am quite fond of Cloanto Currency Server for the actual conversion.
For the formatting, I would take the NumberFormatInfo of the user's culture, and change the currency symbol, but leave everything else exactly as is. Because a user's expectations of the way numbers work does not change just because they convert, and although some would understand the differences in formatting, others wouldn't. And the ones who wouldn't could easily end up misunderstanding the data they are seeing....
But taking a step back, it is really not such a big deal here.
At least for most situations.
You might be wondering why I say that if I talk about the potential for confusion and such?
Well, it is true that I might misunderstand the currency value if things like decimal places change
But think about the scenario for a moment:
I'm trying to display prices, in a currency the user chooses.
This kind of implies the typical online commerce scenario, when most commonly one is converting from some unknown currency into their own. And in this case, for the desired target of everything being in a user's own currency with their own formatting, they will be getting the same final results either way.
In short, the difference between "formatting with user preferences" and "formatting with the currency's preferences" disappears when dealing with the user's own currency.
And of course as I mentioned in Show me the [small]money!, a method to get the culture from the currency doesn't exist in the .NET Framework or Windows, so unless you deal with a third party product or do all of the work yourself, the whole "formatting with the currency's preferences" is hardly going to be all that easy to do anyway.
This may be why Jan was doing it himself, in fact!
So now I will take yet another step back and suggest finding some component that does all of the work here. Money gets one into all kinds of regulatory rules and laws about commerce. It is much better to find a component that can help indemnify you if they screw it up, rather than being ruined if one makes a mistake.
Strange advice coming from someone who works for a company with such a huge "let's develop everything here" bent on things, but (a) Microsoft has the time and money to spend on such a plan as wellas money to pay for their mistakes when they make them, and (b) there are several cases where I think they are wrong in this approach....
This blog brought to you by $ (U+0024, aka DOLLAR SIGN)