NSNumberFormatter and localized format problem

  • Hi guys !

    I'm currently fighting with a text field that is supposed to display
    an amount of money. Since the formatters included in Interface
    Builder are unusable (completely buggy), I'm trying to create the
    formatter in code and set my text field to use this formatter.

    I've first initialized my formatter :

    NSNumberFormatter * aFormatter = [[[NSNumberFormatter alloc] init]
    autorelease];

    The problem is that...

    [aFormatter setNumberStyle: NSNumberFormatterCurrencyStyle]

      ...doesn't seem to work. II thought it was supposed to
    automatically format a number to match the International preferences
    set by the user...but it format my numbers as american type numbers
    (1,500.00 instead of 1 500,00 in France).

    So, I've set my formatter this way :

    [ aFormatter setFormat:@"#,###.00;0.00;#,##0.00"];
    [ aFormatter setLocalizesFormat:YES];

    And it doesn't work either. If I enter a number greater than 999 in
    my text field, I have an error message in the console saying that the
    value of the text field should not be nil !

    So I tried to remove the setLocalizesFormat call and changed the
    format to this (to match the french Format) :

    [ aFormatter setFormat:@"# ###,00;0,00;# ##0,00"];

    And this time, the positive numbers are formatted without decimal and
    with te american thousand separator : 1,500 instead of 1 500,00 !

    Am I doing something wrong ? How am I suppposed to display correctly
    formatted amount in my text field ?

    Thanks for your help,

    Eric.
  • On Apr 26, 2006, at 7:42 AM, Eric Morand wrote:

    > Am I doing something wrong ? How am I suppposed to display
    > correctly formatted amount in my text field ?

    -setNumberStyle: only works if you're using an NSNumberFormatter that
    uses the Tiger behavior. Did you try setting the behavior of the
    formatter first?

    Nick Zitzmann
    <http://www.chronosnet.com/>
  • Le 26 avr. 06 à 17:05, Nick Zitzmann a écrit :

    >
    > On Apr 26, 2006, at 7:42 AM, Eric Morand wrote:
    >
    >> Am I doing something wrong ? How am I suppposed to display
    >> correctly formatted amount in my text field ?
    >
    > -setNumberStyle: only works if you're using an NSNumberFormatter
    > that uses the Tiger behavior. Did you try setting the behavior of
    > the formatter first?

    Yes, I've just added it doesn't format anything. If I type 1500 in
    the field, it remains 1500 instead of 1 500,00 €. I just don't get it.

    >
    > Nick Zitzmann
    > <http://www.chronosnet.com/>
    >
    >
    >
    >
  • NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc]
    init] autorelease];

    [numberFormatter setFormatterBehavior: NSNumberFormatterBehavior10_4];
    [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];

    should work.
    also, a got-cha in NSNumberFormatterCurrencyStyle is that when the
    control is set to display with currency style, it has to have the
    input data WITH the currency symbol as well.
    meaning (in US currency) when a user inputs "24.00" it is considered
    inappropriate.
    he/she has to input "$24.00".
    i encountered this problem with my table column, if anyone finds
    anyway around this or my information incorrect, please do let me know.

    Tony S. Wu
    <tonyswu...>

    On Apr 26, 2006, at 2:05 PM, Eric Morand wrote:

    >
    > Le 26 avr. 06 à 17:05, Nick Zitzmann a écrit :
    >
    >>
    >> On Apr 26, 2006, at 7:42 AM, Eric Morand wrote:
    >>
    >>> Am I doing something wrong ? How am I suppposed to display
    >>> correctly formatted amount in my text field ?
    >>
    >> -setNumberStyle: only works if you're using an NSNumberFormatter
    >> that uses the Tiger behavior. Did you try setting the behavior of
    >> the formatter first?
    >
    >
    > Yes, I've just added it doesn't format anything. If I type 1500 in
    > the field, it remains 1500 instead of 1 500,00 €. I just don't get it.
    >
    >
    >>
    >> Nick Zitzmann
    >> <http://www.chronosnet.com/>
    >>
    >>
    >>
    >>
    >
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/<tonyswu...>
    >
    > This email sent to <tonyswu...>
  • I've typed exactly the lines you gave to me on my awakeFromNib :

    - (void)awakeFromNib
    {
    NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc]
    init] autorelease];

    [numberFormatter setFormatterBehavior: NSNumberFormatterBehavior10_4];
    [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];

    [testTF setFormatter:numberFormatter];
    }

    (testF being the text field)

    Now, each time I type a number (I tried typing "1") in the field (and
    the fiel lose the first responder status), I have a sheet that is
    displayed with a format error message (in french is says "Erreur de
    formatage" that should translate in "Formatting error").

    Eric.

    Le 27 avr. 06 à 07:34, Tony S. Wu a écrit :

    > NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc]
    > init] autorelease];
    >
    > [numberFormatter setFormatterBehavior: NSNumberFormatterBehavior10_4];
    > [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
    >
    > should work.
    > also, a got-cha in NSNumberFormatterCurrencyStyle is that when the
    > control is set to display with currency style, it has to have the
    > input data WITH the currency symbol as well.
    > meaning (in US currency) when a user inputs "24.00" it is
    > considered inappropriate.
    > he/she has to input "$24.00".
    > i encountered this problem with my table column, if anyone finds
    > anyway around this or my information incorrect, please do let me know.
    >
    > Tony S. Wu
    > <tonyswu...>
    >
    >
    >
    > On Apr 26, 2006, at 2:05 PM, Eric Morand wrote:
    >
    >>
    >> Le 26 avr. 06 à 17:05, Nick Zitzmann a écrit :
    >>
    >>>
    >>> On Apr 26, 2006, at 7:42 AM, Eric Morand wrote:
    >>>
    >>>> Am I doing something wrong ? How am I suppposed to display
    >>>> correctly formatted amount in my text field ?
    >>>
    >>> -setNumberStyle: only works if you're using an NSNumberFormatter
    >>> that uses the Tiger behavior. Did you try setting the behavior of
    >>> the formatter first?
    >>
    >>
    >> Yes, I've just added it doesn't format anything. If I type 1500 in
    >> the field, it remains 1500 instead of 1 500,00 €. I just don't get
    >> it.
    >>
    >>
    >>>
    >>> Nick Zitzmann
    >>> <http://www.chronosnet.com/>
    >>>
    >>>
    >>>
    >>>
    >>
    >> _______________________________________________
    >> Do not post admin requests to the list. They will be ignored.
    >> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >> Help/Unsubscribe/Update your Subscription:
    >> http://lists.apple.com/mailman/options/cocoa-dev/<tonyswu...>
    >>
    >> This email sent to <tonyswu...>
    >
  • exactly.
    you have to type in $1 instead of 1 (pointed out by mmalcolm).
    this is a problem i encountered before.
    i don't know why it's so restricted and couldn't figure out how to
    solve it, and ended up abandoning NSNumberFormatterCurrencyStyle.
    if anyone could offer a work around, i'd very much appreciate it.

    Tony S. Wu
    <tonyswu...>

    On Apr 27, 2006, at 12:36 AM, Eric Morand wrote:
    > I've typed exactly the lines you gave to me on my awakeFromNib :
    >
    > - (void)awakeFromNib
    > {
    > NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc]
    > init] autorelease];
    >
    > [numberFormatter setFormatterBehavior:
    > NSNumberFormatterBehavior10_4];
    > [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
    >
    > [testTF setFormatter:numberFormatter];
    > }
    >
    > (testF being the text field)
    >
    > Now, each time I type a number (I tried typing "1") in the field
    > (and the fiel lose the first responder status), I have a sheet that
    > is displayed with a format error message (in french is says "Erreur
    > de formatage" that should translate in "Formatting error").
    >
    >
    >
    >
    > Eric.
    >
    >
    > Le 27 avr. 06 à 07:34, Tony S. Wu a écrit :
    >
    >> NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc]
    >> init] autorelease];
    >>
    >> [numberFormatter setFormatterBehavior:
    >> NSNumberFormatterBehavior10_4];
    >> [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
    >>
    >> should work.
    >> also, a got-cha in NSNumberFormatterCurrencyStyle is that when the
    >> control is set to display with currency style, it has to have the
    >> input data WITH the currency symbol as well.
    >> meaning (in US currency) when a user inputs "24.00" it is
    >> considered inappropriate.
    >> he/she has to input "$24.00".
    >> i encountered this problem with my table column, if anyone finds
    >> anyway around this or my information incorrect, please do let me
    >> know.
    >>
    >> Tony S. Wu
    >> <tonyswu...>
    >>
    >>
    >>
    >> On Apr 26, 2006, at 2:05 PM, Eric Morand wrote:
    >>
    >>>
    >>> Le 26 avr. 06 à 17:05, Nick Zitzmann a écrit :
    >>>
    >>>>
    >>>> On Apr 26, 2006, at 7:42 AM, Eric Morand wrote:
    >>>>
    >>>>> Am I doing something wrong ? How am I suppposed to display
    >>>>> correctly formatted amount in my text field ?
    >>>>
    >>>> -setNumberStyle: only works if you're using an NSNumberFormatter
    >>>> that uses the Tiger behavior. Did you try setting the behavior
    >>>> of the formatter first?
    >>>
    >>>
    >>> Yes, I've just added it doesn't format anything. If I type 1500
    >>> in the field, it remains 1500 instead of 1 500,00 €. I just don't
    >>> get it.
    >>>
    >>>
    >>>>
    >>>> Nick Zitzmann
    >>>> <http://www.chronosnet.com/>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>
    >>> _______________________________________________
    >>> Do not post admin requests to the list. They will be ignored.
    >>> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >>> Help/Unsubscribe/Update your Subscription:
    >>> http://lists.apple.com/mailman/options/cocoa-dev/<tonyswu...>
    >>>
    >>> This email sent to <tonyswu...>
    >>
    >
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/<tonyswu...>
    >
    > This email sent to <tonyswu...>
  • Hi All.

    This is a basic flaw in the design of formatters in general.
    Formatters should have separate, multiple, input formats and a single
    output format. Or maybe multiple, localization dependent, output
    formats. It is not too difficult to write your own formatter. There
    are only a couple of methods to implement. I once wrote a date
    formatter using flex that could recognize many different date
    formats. If you want to use the parsing infrastructure of
    NSNumberFormatter, you could just write a wrapper formatter that
    contains multiple NSNumberFormatters, one for each input format you
    want, and one for the output format.

    -Kenny

    On Apr 27, 2006, at 7:25 AM, Tony S. Wu wrote:

    > exactly.
    > you have to type in $1 instead of 1 (pointed out by mmalcolm).
    > this is a problem i encountered before.
    > i don't know why it's so restricted and couldn't figure out how to
    > solve it, and ended up abandoning NSNumberFormatterCurrencyStyle.
    > if anyone could offer a work around, i'd very much appreciate it.
    >
    > Tony S. Wu
    > <tonyswu...>
    >
    >
    >
    > On Apr 27, 2006, at 12:36 AM, Eric Morand wrote:
    >> I've typed exactly the lines you gave to me on my awakeFromNib :
    >>
    >> - (void)awakeFromNib
    >> {
    >> NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc]
    >> init] autorelease];
    >>
    >> [numberFormatter setFormatterBehavior:
    >> NSNumberFormatterBehavior10_4];
    >> [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
    >>
    >> [testTF setFormatter:numberFormatter];
    >> }
    >>
    >> (testF being the text field)
    >>
    >> Now, each time I type a number (I tried typing "1") in the field
    >> (and the fiel lose the first responder status), I have a sheet
    >> that is displayed with a format error message (in french is says
    >> "Erreur de formatage" that should translate in "Formatting error").
    >>
    >>
    >>
    >>
    >> Eric.
    >>
    >>
    >> Le 27 avr. 06 à 07:34, Tony S. Wu a écrit :
    >>
    >>> NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc]
    >>> init] autorelease];
    >>>
    >>> [numberFormatter setFormatterBehavior:
    >>> NSNumberFormatterBehavior10_4];
    >>> [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
    >>>
    >>> should work.
    >>> also, a got-cha in NSNumberFormatterCurrencyStyle is that when
    >>> the control is set to display with currency style, it has to have
    >>> the input data WITH the currency symbol as well.
    >>> meaning (in US currency) when a user inputs "24.00" it is
    >>> considered inappropriate.
    >>> he/she has to input "$24.00".
    >>> i encountered this problem with my table column, if anyone finds
    >>> anyway around this or my information incorrect, please do let me
    >>> know.
    >>>
    >>> Tony S. Wu
    >>> <tonyswu...>
    >>>
    >>>
    >>>
    >>> On Apr 26, 2006, at 2:05 PM, Eric Morand wrote:
    >>>
    >>>>
    >>>> Le 26 avr. 06 à 17:05, Nick Zitzmann a écrit :
    >>>>
    >>>>>
    >>>>> On Apr 26, 2006, at 7:42 AM, Eric Morand wrote:
    >>>>>
    >>>>>> Am I doing something wrong ? How am I suppposed to display
    >>>>>> correctly formatted amount in my text field ?
    >>>>>
    >>>>> -setNumberStyle: only works if you're using an
    >>>>> NSNumberFormatter that uses the Tiger behavior. Did you try
    >>>>> setting the behavior of the formatter first?
    >>>>
    >>>>
    >>>> Yes, I've just added it doesn't format anything. If I type 1500
    >>>> in the field, it remains 1500 instead of 1 500,00 €. I just
    >>>> don't get it.
    >>>>
    >>>>
    >>>>>
    >>>>> Nick Zitzmann
    >>>>> <http://www.chronosnet.com/>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>
    >>>> _______________________________________________
    >>>> Do not post admin requests to the list. They will be ignored.
    >>>> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >>>> Help/Unsubscribe/Update your Subscription:
    >>>> http://lists.apple.com/mailman/options/cocoa-dev/<tonyswu...>
    >>>>
    >>>> This email sent to <tonyswu...>
    >>>
    >>
    >> _______________________________________________
    >> Do not post admin requests to the list. They will be ignored.
    >> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >> Help/Unsubscribe/Update your Subscription:
    >> http://lists.apple.com/mailman/options/cocoa-dev/<tonyswu...>
    >>
    >> This email sent to <tonyswu...>
    >
    >
    >
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/kenny_leung%
    > 40pobox.com
    >
    > This email sent to <kenny_leung...>
    >
    >
  • I understand what you mean.

    What I don't understand is what is the official (i.e. Apple) method
    to format a number with the localized format of the user ? I can't
    guess what are the number format of every country in the world, right ?

    Le 27 avr. 06 à 17:15, Kenny Leung a écrit :

    > Hi All.
    >
    > This is a basic flaw in the design of formatters in general.
    > Formatters should have separate, multiple, input formats and a
    > single output format. Or maybe multiple, localization dependent,
    > output formats. It is not too difficult to write your own
    > formatter. There are only a couple of methods to implement. I once
    > wrote a date formatter using flex that could recognize many
    > different date formats. If you want to use the parsing
    > infrastructure of NSNumberFormatter, you could just write a wrapper
    > formatter that contains multiple NSNumberFormatters, one for each
    > input format you want, and one for the output format.
    >
    > -Kenny
    >
    >
    > On Apr 27, 2006, at 7:25 AM, Tony S. Wu wrote:
    >
    >> exactly.
    >> you have to type in $1 instead of 1 (pointed out by mmalcolm).
    >> this is a problem i encountered before.
    >> i don't know why it's so restricted and couldn't figure out how to
    >> solve it, and ended up abandoning NSNumberFormatterCurrencyStyle.
    >> if anyone could offer a work around, i'd very much appreciate it.
    >>
    >> Tony S. Wu
    >> <tonyswu...>
    >>
    >>
    >>
    >> On Apr 27, 2006, at 12:36 AM, Eric Morand wrote:
    >>> I've typed exactly the lines you gave to me on my awakeFromNib :
    >>>
    >>> - (void)awakeFromNib
    >>> {
    >>> NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc]
    >>> init] autorelease];
    >>>
    >>> [numberFormatter setFormatterBehavior:
    >>> NSNumberFormatterBehavior10_4];
    >>> [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
    >>>
    >>> [testTF setFormatter:numberFormatter];
    >>> }
    >>>
    >>> (testF being the text field)
    >>>
    >>> Now, each time I type a number (I tried typing "1") in the field
    >>> (and the fiel lose the first responder status), I have a sheet
    >>> that is displayed with a format error message (in french is says
    >>> "Erreur de formatage" that should translate in "Formatting error").
    >>>
    >>>
    >>>
    >>>
    >>> Eric.
    >>>
    >>>
    >>> Le 27 avr. 06 à 07:34, Tony S. Wu a écrit :
    >>>
    >>>> NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc]
    >>>> init] autorelease];
    >>>>
    >>>> [numberFormatter setFormatterBehavior:
    >>>> NSNumberFormatterBehavior10_4];
    >>>> [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
    >>>>
    >>>> should work.
    >>>> also, a got-cha in NSNumberFormatterCurrencyStyle is that when
    >>>> the control is set to display with currency style, it has to
    >>>> have the input data WITH the currency symbol as well.
    >>>> meaning (in US currency) when a user inputs "24.00" it is
    >>>> considered inappropriate.
    >>>> he/she has to input "$24.00".
    >>>> i encountered this problem with my table column, if anyone finds
    >>>> anyway around this or my information incorrect, please do let me
    >>>> know.
    >>>>
    >>>> Tony S. Wu
    >>>> <tonyswu...>
    >>>>
    >>>>
    >>>>
    >>>> On Apr 26, 2006, at 2:05 PM, Eric Morand wrote:
    >>>>
    >>>>>
    >>>>> Le 26 avr. 06 à 17:05, Nick Zitzmann a écrit :
    >>>>>
    >>>>>>
    >>>>>> On Apr 26, 2006, at 7:42 AM, Eric Morand wrote:
    >>>>>>
    >>>>>>> Am I doing something wrong ? How am I suppposed to display
    >>>>>>> correctly formatted amount in my text field ?
    >>>>>>
    >>>>>> -setNumberStyle: only works if you're using an
    >>>>>> NSNumberFormatter that uses the Tiger behavior. Did you try
    >>>>>> setting the behavior of the formatter first?
    >>>>>
    >>>>>
    >>>>> Yes, I've just added it doesn't format anything. If I type 1500
    >>>>> in the field, it remains 1500 instead of 1 500,00 €. I just
    >>>>> don't get it.
    >>>>>
    >>>>>
    >>>>>>
    >>>>>> Nick Zitzmann
    >>>>>> <http://www.chronosnet.com/>
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>
    >>>>> _______________________________________________
    >>>>> Do not post admin requests to the list. They will be ignored.
    >>>>> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >>>>> Help/Unsubscribe/Update your Subscription:
    >>>>> http://lists.apple.com/mailman/options/cocoa-dev/<tonyswu...>
    >>>>>
    >>>>> This email sent to <tonyswu...>
    >>>>
    >>>
    >>> _______________________________________________
    >>> Do not post admin requests to the list. They will be ignored.
    >>> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >>> Help/Unsubscribe/Update your Subscription:
    >>> http://lists.apple.com/mailman/options/cocoa-dev/<tonyswu...>
    >>>
    >>> This email sent to <tonyswu...>
    >>
    >>
    >>
    >> _______________________________________________
    >> Do not post admin requests to the list. They will be ignored.
    >> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >> Help/Unsubscribe/Update your Subscription:
    >> http://lists.apple.com/mailman/options/cocoa-dev/kenny_leung%
    >> 40pobox.com
    >>
    >> This email sent to <kenny_leung...>
    >>
    >>
    >
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/<eric.morand...>
    >
    > This email sent to <eric.morand...>
  • How about setLocalizesFormat:?

    "Sets whether the dollar sign character ($), decimal separator
    character (.), and thousand separator character (,) are converted to
    appropriately localized characters as specified by the user’s
    localization preference."

    -Kenny

    On Apr 27, 2006, at 11:49 AM, Eric Morand wrote:

    >
    > I understand what you mean.
    >
    > What I don't understand is what is the official (i.e. Apple) method
    > to format a number with the localized format of the user ? I can't
    > guess what are the number format of every country in the world,
    > right ?
    >
    >
    >
    > Le 27 avr. 06 à 17:15, Kenny Leung a écrit :
    >
    >> Hi All.
    >>
    >> This is a basic flaw in the design of formatters in general.
    >> Formatters should have separate, multiple, input formats and a
    >> single output format. Or maybe multiple, localization dependent,
    >> output formats. It is not too difficult to write your own
    >> formatter. There are only a couple of methods to implement. I once
    >> wrote a date formatter using flex that could recognize many
    >> different date formats. If you want to use the parsing
    >> infrastructure of NSNumberFormatter, you could just write a
    >> wrapper formatter that contains multiple NSNumberFormatters, one
    >> for each input format you want, and one for the output format.
    >>
    >> -Kenny
    >>
    >>
    >> On Apr 27, 2006, at 7:25 AM, Tony S. Wu wrote:
    >>
    >>> exactly.
    >>> you have to type in $1 instead of 1 (pointed out by mmalcolm).
    >>> this is a problem i encountered before.
    >>> i don't know why it's so restricted and couldn't figure out how
    >>> to solve it, and ended up abandoning NSNumberFormatterCurrencyStyle.
    >>> if anyone could offer a work around, i'd very much appreciate it.
    >>>
    >>> Tony S. Wu
    >>> <tonyswu...>
    >>>
    >>>
    >>>
    >>> On Apr 27, 2006, at 12:36 AM, Eric Morand wrote:
    >>>> I've typed exactly the lines you gave to me on my awakeFromNib :
    >>>>
    >>>> - (void)awakeFromNib
    >>>> {
    >>>> NSNumberFormatter *numberFormatter = [[[NSNumberFormatter
    >>>> alloc] init] autorelease];
    >>>>
    >>>> [numberFormatter setFormatterBehavior:
    >>>> NSNumberFormatterBehavior10_4];
    >>>> [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
    >>>>
    >>>> [testTF setFormatter:numberFormatter];
    >>>> }
    >>>>
    >>>> (testF being the text field)
    >>>>
    >>>> Now, each time I type a number (I tried typing "1") in the field
    >>>> (and the fiel lose the first responder status), I have a sheet
    >>>> that is displayed with a format error message (in french is says
    >>>> "Erreur de formatage" that should translate in "Formatting error").
    >>>>
    >>>>
    >>>>
    >>>>
    >>>> Eric.
    >>>>
    >>>>
    >>>> Le 27 avr. 06 à 07:34, Tony S. Wu a écrit :
    >>>>
    >>>>> NSNumberFormatter *numberFormatter = [[[NSNumberFormatter
    >>>>> alloc] init] autorelease];
    >>>>>
    >>>>> [numberFormatter setFormatterBehavior:
    >>>>> NSNumberFormatterBehavior10_4];
    >>>>> [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
    >>>>>
    >>>>> should work.
    >>>>> also, a got-cha in NSNumberFormatterCurrencyStyle is that when
    >>>>> the control is set to display with currency style, it has to
    >>>>> have the input data WITH the currency symbol as well.
    >>>>> meaning (in US currency) when a user inputs "24.00" it is
    >>>>> considered inappropriate.
    >>>>> he/she has to input "$24.00".
    >>>>> i encountered this problem with my table column, if anyone
    >>>>> finds anyway around this or my information incorrect, please do
    >>>>> let me know.
    >>>>>
    >>>>> Tony S. Wu
    >>>>> <tonyswu...>
    >>>>>
    >>>>>
    >>>>>
    >>>>> On Apr 26, 2006, at 2:05 PM, Eric Morand wrote:
    >>>>>
    >>>>>>
    >>>>>> Le 26 avr. 06 à 17:05, Nick Zitzmann a écrit :
    >>>>>>
    >>>>>>>
    >>>>>>> On Apr 26, 2006, at 7:42 AM, Eric Morand wrote:
    >>>>>>>
    >>>>>>>> Am I doing something wrong ? How am I suppposed to display
    >>>>>>>> correctly formatted amount in my text field ?
    >>>>>>>
    >>>>>>> -setNumberStyle: only works if you're using an
    >>>>>>> NSNumberFormatter that uses the Tiger behavior. Did you try
    >>>>>>> setting the behavior of the formatter first?
    >>>>>>
    >>>>>>
    >>>>>> Yes, I've just added it doesn't format anything. If I type
    >>>>>> 1500 in the field, it remains 1500 instead of 1 500,00 €. I
    >>>>>> just don't get it.
    >>>>>>
    >>>>>>
    >>>>>>>
    >>>>>>> Nick Zitzmann
    >>>>>>> <http://www.chronosnet.com/>
    >>>>>>>
    >>>>>>>
    >>>>>>>
    >>>>>>>
    >>>>>>
    >>>>>> _______________________________________________
    >>>>>> Do not post admin requests to the list. They will be ignored.
    >>>>>> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >>>>>> Help/Unsubscribe/Update your Subscription:
    >>>>>> http://lists.apple.com/mailman/options/cocoa-dev/tonyswu%
    >>>>>> 40mac.com
    >>>>>>
    >>>>>> This email sent to <tonyswu...>
    >>>>>
    >>>>
    >>>> _______________________________________________
    >>>> Do not post admin requests to the list. They will be ignored.
    >>>> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >>>> Help/Unsubscribe/Update your Subscription:
    >>>> http://lists.apple.com/mailman/options/cocoa-dev/<tonyswu...>
    >>>>
    >>>> This email sent to <tonyswu...>
    >>>
    >>>
    >>>
    >>> _______________________________________________
    >>> Do not post admin requests to the list. They will be ignored.
    >>> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >>> Help/Unsubscribe/Update your Subscription:
    >>> http://lists.apple.com/mailman/options/cocoa-dev/kenny_leung%
    >>> 40pobox.com
    >>>
    >>> This email sent to <kenny_leung...>
    >>>
    >>>
    >>
    >> _______________________________________________
    >> Do not post admin requests to the list. They will be ignored.
    >> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >> Help/Unsubscribe/Update your Subscription:
    >> http://lists.apple.com/mailman/options/cocoa-dev/eric.morand%
    >> 40mac.com
    >>
    >> This email sent to <eric.morand...>
    >
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/kenny_leung%
    > 40pobox.com
    >
    > This email sent to <kenny_leung...>
    >
    >
  • It doesn't work.

    As I've said earlier, here is what I tried :

    [ aFormatter setFormat:@"#,###.00 $;0.00 $;#,##0.00 $"];
    [ aFormatter setLocalizesFormat:YES];

    If I type 150 in my test field, the formatter correctly format to
    150,00 €.

    But if I type a number greater than 999, the formatter returns nil.

    Le 27 avr. 06 à 21:10, Kenny Leung a écrit :

    > How about setLocalizesFormat:?
    >
    > "Sets whether the dollar sign character ($), decimal separator
    > character (.), and thousand separator character (,) are converted
    > to appropriately localized characters as specified by the user’s
    > localization preference."
    >
    > -Kenny
    >
    >
    > On Apr 27, 2006, at 11:49 AM, Eric Morand wrote:
    >
    >>
    >> I understand what you mean.
    >>
    >> What I don't understand is what is the official (i.e. Apple)
    >> method to format a number with the localized format of the user ?
    >> I can't guess what are the number format of every country in the
    >> world, right ?
    >>
    >>
    >>
    >> Le 27 avr. 06 à 17:15, Kenny Leung a écrit :
    >>
    >>> Hi All.
    >>>
    >>> This is a basic flaw in the design of formatters in general.
    >>> Formatters should have separate, multiple, input formats and a
    >>> single output format. Or maybe multiple, localization dependent,
    >>> output formats. It is not too difficult to write your own
    >>> formatter. There are only a couple of methods to implement. I
    >>> once wrote a date formatter using flex that could recognize many
    >>> different date formats. If you want to use the parsing
    >>> infrastructure of NSNumberFormatter, you could just write a
    >>> wrapper formatter that contains multiple NSNumberFormatters, one
    >>> for each input format you want, and one for the output format.
    >>>
    >>> -Kenny
    >>>
    >>>
    >>> On Apr 27, 2006, at 7:25 AM, Tony S. Wu wrote:
    >>>
    >>>> exactly.
    >>>> you have to type in $1 instead of 1 (pointed out by mmalcolm).
    >>>> this is a problem i encountered before.
    >>>> i don't know why it's so restricted and couldn't figure out how
    >>>> to solve it, and ended up abandoning
    >>>> NSNumberFormatterCurrencyStyle.
    >>>> if anyone could offer a work around, i'd very much appreciate it.
    >>>>
    >>>> Tony S. Wu
    >>>> <tonyswu...>
    >>>>
    >>>>
    >>>>
    >>>> On Apr 27, 2006, at 12:36 AM, Eric Morand wrote:
    >>>>> I've typed exactly the lines you gave to me on my awakeFromNib :
    >>>>>
    >>>>> - (void)awakeFromNib
    >>>>> {
    >>>>> NSNumberFormatter *numberFormatter = [[[NSNumberFormatter
    >>>>> alloc] init] autorelease];
    >>>>>
    >>>>> [numberFormatter setFormatterBehavior:
    >>>>> NSNumberFormatterBehavior10_4];
    >>>>> [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
    >>>>>
    >>>>> [testTF setFormatter:numberFormatter];
    >>>>> }
    >>>>>
    >>>>> (testF being the text field)
    >>>>>
    >>>>> Now, each time I type a number (I tried typing "1") in the
    >>>>> field (and the fiel lose the first responder status), I have a
    >>>>> sheet that is displayed with a format error message (in french
    >>>>> is says "Erreur de formatage" that should translate in
    >>>>> "Formatting error").
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>> Eric.
    >>>>>
    >>>>>
    >>>>> Le 27 avr. 06 à 07:34, Tony S. Wu a écrit :
    >>>>>
    >>>>>> NSNumberFormatter *numberFormatter = [[[NSNumberFormatter
    >>>>>> alloc] init] autorelease];
    >>>>>>
    >>>>>> [numberFormatter setFormatterBehavior:
    >>>>>> NSNumberFormatterBehavior10_4];
    >>>>>> [numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle];
    >>>>>>
    >>>>>> should work.
    >>>>>> also, a got-cha in NSNumberFormatterCurrencyStyle is that when
    >>>>>> the control is set to display with currency style, it has to
    >>>>>> have the input data WITH the currency symbol as well.
    >>>>>> meaning (in US currency) when a user inputs "24.00" it is
    >>>>>> considered inappropriate.
    >>>>>> he/she has to input "$24.00".
    >>>>>> i encountered this problem with my table column, if anyone
    >>>>>> finds anyway around this or my information incorrect, please
    >>>>>> do let me know.
    >>>>>>
    >>>>>> Tony S. Wu
    >>>>>> <tonyswu...>
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>> On Apr 26, 2006, at 2:05 PM, Eric Morand wrote:
    >>>>>>
    >>>>>>>
    >>>>>>> Le 26 avr. 06 à 17:05, Nick Zitzmann a écrit :
    >>>>>>>
    >>>>>>>>
    >>>>>>>> On Apr 26, 2006, at 7:42 AM, Eric Morand wrote:
    >>>>>>>>
    >>>>>>>>> Am I doing something wrong ? How am I suppposed to display
    >>>>>>>>> correctly formatted amount in my text field ?
    >>>>>>>>
    >>>>>>>> -setNumberStyle: only works if you're using an
    >>>>>>>> NSNumberFormatter that uses the Tiger behavior. Did you try
    >>>>>>>> setting the behavior of the formatter first?
    >>>>>>>
    >>>>>>>
    >>>>>>> Yes, I've just added it doesn't format anything. If I type
    >>>>>>> 1500 in the field, it remains 1500 instead of 1 500,00 €. I
    >>>>>>> just don't get it.
    >>>>>>>
    >>>>>>>
    >>>>>>>>
    >>>>>>>> Nick Zitzmann
    >>>>>>>> <http://www.chronosnet.com/>
    >>>>>>>>
    >>>>>>>>
    >>>>>>>>
    >>>>>>>>
    >>>>>>>
    >>>>>>> _______________________________________________
    >>>>>>> Do not post admin requests to the list. They will be ignored.
    >>>>>>> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >>>>>>> Help/Unsubscribe/Update your Subscription:
    >>>>>>> http://lists.apple.com/mailman/options/cocoa-dev/tonyswu%
    >>>>>>> 40mac.com
    >>>>>>>
    >>>>>>> This email sent to <tonyswu...>
    >>>>>>
    >>>>>
    >>>>> _______________________________________________
    >>>>> Do not post admin requests to the list. They will be ignored.
    >>>>> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >>>>> Help/Unsubscribe/Update your Subscription:
    >>>>> http://lists.apple.com/mailman/options/cocoa-dev/<tonyswu...>
    >>>>>
    >>>>> This email sent to <tonyswu...>
    >>>>
    >>>>
    >>>>
    >>>> _______________________________________________
    >>>> Do not post admin requests to the list. They will be ignored.
    >>>> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >>>> Help/Unsubscribe/Update your Subscription:
    >>>> http://lists.apple.com/mailman/options/cocoa-dev/kenny_leung%
    >>>> 40pobox.com
    >>>>
    >>>> This email sent to <kenny_leung...>
    >>>>
    >>>>
    >>>
    >>> _______________________________________________
    >>> Do not post admin requests to the list. They will be ignored.
    >>> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >>> Help/Unsubscribe/Update your Subscription:
    >>> http://lists.apple.com/mailman/options/cocoa-dev/eric.morand%
    >>> 40mac.com
    >>>
    >>> This email sent to <eric.morand...>
    >>
    >> _______________________________________________
    >> Do not post admin requests to the list. They will be ignored.
    >> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >> Help/Unsubscribe/Update your Subscription:
    >> http://lists.apple.com/mailman/options/cocoa-dev/kenny_leung%
    >> 40pobox.com
    >>
    >> This email sent to <kenny_leung...>
    >>
    >>
    >
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/<eric.morand...>
    >
    > This email sent to <eric.morand...>
  • Don't use setFormat: and setLocalizesFormat: with a 10_4 behavior
    NSNumberFormatter.  Those are old methods for compatibility with old-
    style behavior formatters.  They may do something similar to what
    happened with an old-behavior formatter, on a new-behavior formatter,
    but it's better to use the new methods (like setLocale:) with a new-
    behavior formatter for more accurate results.

    With 10_0 behavior formatters, there is an ancient bug where it won't
    parse input with the formatter's own thousands separator in it.
    That's not a problem when you're typing a number greater than 999,
    because you probably aren't including the thousand separator.  But
    nowdays, for whatever reason, AppKit parsers and formats the user's
    input several times through the formatter, and one of these stages
    passes the formatter's output back into the formatter, and the
    formatter can't parse it's own output (depends a bit on how it's set
    up).

    Somebody else was hitting this recently.  I suggested a workaround
    might be (but didn't try it) to subclass NSNumberFormatter, override
    the getObjectValue:... method, strip out the thousand separator from
    the string parameter, then call super getObjectValue:... with the
    result.

    I agree with Tony Wu, too, that the currency symbol shouldn't be
    required in user input (and should be assumed to be the locale's
    default currency).  There's no lenient number parsing setting in the
    ICU API, so I don't know if there's a way for NSNumberFormatter to
    turn that requirement off for a currency-style formatter.  I also
    agree with Kenny Leung that formatters should have multiple input
    formats, and there's an enhancement request or two about that, but
    enhancing formatters in that way has never been high enough priority
    for anybody to get to it.

    Chris Kane
    Cocoa Frameworks, Apple

    On Apr 27, 2006, at 2:16 PM, Eric Morand wrote:

    > It doesn't work.
    >
    > As I've said earlier, here is what I tried :
    >
    > [ aFormatter setFormat:@"#,###.00 $;0.00 $;#,##0.00 $"];
    > [ aFormatter setLocalizesFormat:YES];
    >
    > If I type 150 in my test field, the formatter correctly format to
    > 150,00 €.
    >
    > But if I type a number greater than 999, the formatter returns nil.
    >
    >
    >
    >
    >
    > Le 27 avr. 06 à 21:10, Kenny Leung a écrit :
    >
    >> How about setLocalizesFormat:?
    >>
    >> "Sets whether the dollar sign character ($), decimal separator
    >> character (.), and thousand separator character (,) are converted
    >> to appropriately localized characters as specified by the user’s
    >> localization preference."
    >>
    >> -Kenny
    >>
    >>
    >> On Apr 27, 2006, at 11:49 AM, Eric Morand wrote:
    >>
    >>>
    >>> I understand what you mean.
    >>>
    >>> What I don't understand is what is the official (i.e. Apple)
    >>> method to format a number with the localized format of the user ?
    >>> I can't guess what are the number format of every country in the
    >>> world, right ?
    >>>
    >>>
    >>>
    >>> Le 27 avr. 06 à 17:15, Kenny Leung a écrit :
    >>>
    >>>> Hi All.
    >>>>
    >>>> This is a basic flaw in the design of formatters in general.
    >>>> Formatters should have separate, multiple, input formats and a
    >>>> single output format. Or maybe multiple, localization dependent,
    >>>> output formats. It is not too difficult to write your own
    >>>> formatter. There are only a couple of methods to implement. I
    >>>> once wrote a date formatter using flex that could recognize many
    >>>> different date formats. If you want to use the parsing
    >>>> infrastructure of NSNumberFormatter, you could just write a
    >>>> wrapper formatter that contains multiple NSNumberFormatters, one
    >>>> for each input format you want, and one for the output format.
    >>>>
    >>>> -Kenny
    >>>>
    >>>>
    >>>> On Apr 27, 2006, at 7:25 AM, Tony S. Wu wrote:
    >>>>
    >>>>> exactly.
    >>>>> you have to type in $1 instead of 1 (pointed out by mmalcolm).
    >>>>> this is a problem i encountered before.
    >>>>> i don't know why it's so restricted and couldn't figure out how
    >>>>> to solve it, and ended up abandoning
    >>>>> NSNumberFormatterCurrencyStyle.
    >>>>> if anyone could offer a work around, i'd very much appreciate it.
    >>>>>
    >>>>> Tony S. Wu
    >>>>> <tonyswu...>
    >>>>>
    >>>>>
    >>>>>
    >>>>> On Apr 27, 2006, at 12:36 AM, Eric Morand wrote:
    >>>>>> I've typed exactly the lines you gave to me on my awakeFromNib :
    >>>>>>
    >>>>>> - (void)awakeFromNib
    >>>>>> {
    >>>>>> NSNumberFormatter *numberFormatter = [[[NSNumberFormatter
    >>>>>> alloc] init] autorelease];
    >>>>>>
    >>>>>> [numberFormatter setFormatterBehavior:
    >>>>>> NSNumberFormatterBehavior10_4];
    >>>>>> [numberFormatter setNumberStyle:
    >>>>>> NSNumberFormatterCurrencyStyle];
    >>>>>>
    >>>>>> [testTF setFormatter:numberFormatter];
    >>>>>> }
    >>>>>>
    >>>>>> (testF being the text field)
    >>>>>>
    >>>>>> Now, each time I type a number (I tried typing "1") in the
    >>>>>> field (and the fiel lose the first responder status), I have a
    >>>>>> sheet that is displayed with a format error message (in french
    >>>>>> is says "Erreur de formatage" that should translate in
    >>>>>> "Formatting error").
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>> Eric.
    >>>>>>
    >>>>>>
    >>>>>> Le 27 avr. 06 à 07:34, Tony S. Wu a écrit :
    >>>>>>
    >>>>>>> NSNumberFormatter *numberFormatter = [[[NSNumberFormatter
    >>>>>>> alloc] init] autorelease];
    >>>>>>>
    >>>>>>> [numberFormatter setFormatterBehavior:
    >>>>>>> NSNumberFormatterBehavior10_4];
    >>>>>>> [numberFormatter setNumberStyle:
    >>>>>>> NSNumberFormatterCurrencyStyle];
    >>>>>>>
    >>>>>>> should work.
    >>>>>>> also, a got-cha in NSNumberFormatterCurrencyStyle is that
    >>>>>>> when the control is set to display with currency style, it
    >>>>>>> has to have the input data WITH the currency symbol as well.
    >>>>>>> meaning (in US currency) when a user inputs "24.00" it is
    >>>>>>> considered inappropriate.
    >>>>>>> he/she has to input "$24.00".
    >>>>>>> i encountered this problem with my table column, if anyone
    >>>>>>> finds anyway around this or my information incorrect, please
    >>>>>>> do let me know.
    >>>>>>>
    >>>>>>> Tony S. Wu
    >>>>>>> <tonyswu...>
    >>>>>>>
    >>>>>>>
    >>>>>>>
    >>>>>>> On Apr 26, 2006, at 2:05 PM, Eric Morand wrote:
    >>>>>>>
    >>>>>>>>
    >>>>>>>> Le 26 avr. 06 à 17:05, Nick Zitzmann a écrit :
    >>>>>>>>
    >>>>>>>>>
    >>>>>>>>> On Apr 26, 2006, at 7:42 AM, Eric Morand wrote:
    >>>>>>>>>
    >>>>>>>>>> Am I doing something wrong ? How am I suppposed to display
    >>>>>>>>>> correctly formatted amount in my text field ?
    >>>>>>>>>
    >>>>>>>>> -setNumberStyle: only works if you're using an
    >>>>>>>>> NSNumberFormatter that uses the Tiger behavior. Did you try
    >>>>>>>>> setting the behavior of the formatter first?
    >>>>>>>>
    >>>>>>>>
    >>>>>>>> Yes, I've just added it doesn't format anything. If I type
    >>>>>>>> 1500 in the field, it remains 1500 instead of 1 500,00 €. I
    >>>>>>>> just don't get it.
    >>>>>>>>
    >>>>>>>>
    >>>>>>>>>
    >>>>>>>>> Nick Zitzmann
    >>>>>>>>> <http://www.chronosnet.com/>
    >>>>>>>>>
    >>>>>>>>>
    >>>>>>>>>
    >>>>>>>>>
    >>>>>>>>
    >>>>>>>> _______________________________________________
    >>>>>>>> Do not post admin requests to the list. They will be ignored.
    >>>>>>>> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >>>>>>>> Help/Unsubscribe/Update your Subscription:
    >>>>>>>> http://lists.apple.com/mailman/options/cocoa-dev/tonyswu%
    >>>>>>>> 40mac.com
    >>>>>>>>
    >>>>>>>> This email sent to <tonyswu...>
    >>>>>>>
    >>>>>>
    >>>>>> _______________________________________________
    >>>>>> Do not post admin requests to the list. They will be ignored.
    >>>>>> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >>>>>> Help/Unsubscribe/Update your Subscription:
    >>>>>> http://lists.apple.com/mailman/options/cocoa-dev/tonyswu%
    >>>>>> 40mac.com
    >>>>>>
    >>>>>> This email sent to <tonyswu...>
    >>>>>
    >>>>>
    >>>>>
    >>>>> _______________________________________________
    >>>>> Do not post admin requests to the list. They will be ignored.
    >>>>> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >>>>> Help/Unsubscribe/Update your Subscription:
    >>>>> http://lists.apple.com/mailman/options/cocoa-dev/kenny_leung%
    >>>>> 40pobox.com
    >>>>>
    >>>>> This email sent to <kenny_leung...>
    >>>>>
    >>>>>
    >>>>
    >>>> _______________________________________________
    >>>> Do not post admin requests to the list. They will be ignored.
    >>>> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >>>> Help/Unsubscribe/Update your Subscription:
    >>>> http://lists.apple.com/mailman/options/cocoa-dev/eric.morand%
    >>>> 40mac.com
    >>>>
    >>>> This email sent to <eric.morand...>
    >>>
    >>> _______________________________________________
    >>> Do not post admin requests to the list. They will be ignored.
    >>> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >>> Help/Unsubscribe/Update your Subscription:
    >>> http://lists.apple.com/mailman/options/cocoa-dev/kenny_leung%
    >>> 40pobox.com
    >>>
    >>> This email sent to <kenny_leung...>
    >>>
    >>>
    >>
    >> _______________________________________________
    >> Do not post admin requests to the list. They will be ignored.
    >> Cocoa-dev mailing list      (<Cocoa-dev...>)
    >> Help/Unsubscribe/Update your Subscription:
    >> http://lists.apple.com/mailman/options/cocoa-dev/eric.morand%
    >> 40mac.com
    >>
    >> This email sent to <eric.morand...>
    >
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/<ckane...>
    >
    > This email sent to <ckane...>