• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Adding text in NSNumberFormatter string - 'e' not allowed?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Adding text in NSNumberFormatter string - 'e' not allowed?


  • Subject: Re: Adding text in NSNumberFormatter string - 'e' not allowed?
  • From: Serge Meynard <email@hidden>
  • Date: Sat, 02 Apr 2005 11:51:41 -0500

On Apr 2, 2005, at 09:07, Rick Hoge wrote:

Recently it occurred to me that it would be useful to add text in the Interface Builder format field for number formatters.


For example instead of "#,##0.00" in the field for Positive I might "#,##0.00 kilometres" or something (to have units added).

What seems to happen is that the letter 'e' is removed from the text when the edit is committed by tabbing out of the field, so I get "#,##0.00 kilomtrs"

I am guessing that 'e' is some kind of reserved character, but I can't find a reference to this usage in the docs. So my two questions are:

1)  is this a dangerous misuse of NSNumberFormatter?

2) if not, is there any way I can quote characters or strings to have them included in the format string?

Thanks for any suggestions,

Rick

I'm willing to bet that 'e' is reserved for exponents in scientific notation (i.e. 1234.5e+4).


I don't know if putting text in a format string is "dangerous", but I also doubt it's intended, since there is no mention of it. Why not just write your own formatter? If you were willing to add "kilometres" in the format string, then by extension you're willing to be inflexible (since "km" would not have worked). So just create a subclass of NSNumberFormatter, append "kilometres" when you convert from value to string, and validate/strip "kilometres" from the end of the text before processing when converting from string to value. If you really want to be user-friendly, you could also allow for alternate spellings ("km", "kilom", whatever), extra whitespace, etc. After you do all that, you'll probably get user requests for allowing other units to be typed in and automatically converted, so you'll add more code... and eventually you'll start to wish you had just stuck with a standard number formatter and spent your coding time on more interesting stuff :)

Serge

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Adding text in NSNumberFormatter string - 'e' not allowed? (From: Rick Hoge <email@hidden>)

  • Prev by Date: Re: Dictionary Saving Horribly Slow!?
  • Next by Date: WWDC 2005 - Is the value worth the price? (OT)
  • Previous by thread: Adding text in NSNumberFormatter string - 'e' not allowed?
  • Next by thread: Split view in a table
  • Index(es):
    • Date
    • Thread