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.

No comments: