Ask a questionAsk a question
 

AnswerNumberFormat object flaw?

  • Thursday, September 20, 2007 4:13 PMKev Pearman Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    How can you use a NumberFormat object to get the "pence" symbol for a culture, i.e. en-GB would give "p" and en-US would give "¢". I've been looking through the class in visual studio and can't find anything relating to this, i've also gone through the different ToString() format methods and i can't find anything their either.

    If you have an answer please reply here and drop a comment on my blog


    Cheers

Answers

  • Thursday, September 20, 2007 4:54 PMPeter RitchieMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Windows locale/culture only recognizes currency at the 100 level (i.e. dollars or pounds).  You'll have to manage formatting cents at the application level.

  • Thursday, September 20, 2007 4:59 PMIsshouFuuraibou Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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.

All Replies

  • Thursday, September 20, 2007 4:21 PMH. _冬_ Tony Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I dont think number format can handle that, you need to write your own code to do that.


  • Thursday, September 20, 2007 4:51 PMKev Pearman Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    The problem with writing your own code to do it is if you want to add another currency to your table and they have a different symbol for their "pence", "cent" etc then it will require a code change to hard code the new symbol where as the cultureinfo object will handle any new cultures dynamically.

    If the NumberFormat object can't do this then is there another way of getting the pence / cent symbol dynamically based on the users culture?
  • Thursday, September 20, 2007 4:54 PMPeter RitchieMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Windows locale/culture only recognizes currency at the 100 level (i.e. dollars or pounds).  You'll have to manage formatting cents at the application level.

  • Thursday, September 20, 2007 4:59 PMIsshouFuuraibou Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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.
  • Thursday, September 20, 2007 6:07 PMKev Pearman Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks for your answers, i suppose it makes sense when you think about cultures that don't have a "pence" denomination.