Showing posts with label CultureInfo. Show all posts
Showing posts with label CultureInfo. Show all posts

Friday, 21 September 2007

NumberFormat issue answered

I posted my issue on MSDN to see if anyone knew what i was doing wrong or if there was a workaround but one of the answers i got made some sense as far as explaining the omission of a "pence" symbol on the NumberFormat object.

Posted by IsshouFuuraibou...
I think because "pence" or cent symbol is an exception to the rule and not the standard. In many cases monetary systems don't have "pence" currency. For example the smallest denomination for the Japanese Yen is 1 Yen. This is true in many other currencies. You'll also see that in all cases where you have a "pence" symbol, you can also format it as "$"0.00. From what I've seen the culture info doesn't store the pence symbol.


The full thread is here.

While that is a fairly reasonable explanation it still seems to be a fairly large omission. Although the "pence" symbol is the exception to the rule it is applicable to a large portion of the world, all of Europe Australia, the US. Sounds like a flaw to me, surely you include it where applicable and omit it in the other cases?

Thursday, 20 September 2007

NumberFormat object flaw?

I've been working on some price tables on our website today and we want to make sure everything is formatted correctly based upon the users culture. Obviously you would assume that the the CultureInfo.NumberFormat would be the way to go and, for the most part, it is. If you want to format your numbers to have seperators in to break them up or format a currency string with a currency symbol then you're laughing,

decimal.ToString("N0", cultureInfo) will give you your number with the correct seperators in the correct places i.e. 10000 becomes 10,000 in en-GB culture.
decimal.ToString("C2", cultureInfo) will give you your currency string, i.e. 100.59 becomes £100.59

All is well, or is it? What do you do if you want the "pence" symbol for a culture i.e p or ¢? There is no property on the NumberFormat object to do this for you, at least not that i could find.

Anyone know what i'm missing here or have a decent workaround? I've got by for now with string manipulation but that involves hard coding the p or ¢ into the code. If we decide to introduce a new currency with a different symbol then it will require a code change.