Re: NSNumberFormatter -setZeroSymbol:
Re: NSNumberFormatter -setZeroSymbol:
- Subject: Re: NSNumberFormatter -setZeroSymbol:
- From: Chris Kane <email@hidden>
- Date: Sat, 4 Aug 2007 09:14:01 -0700
Actually, it doesn't do what Marcus thinks it does, but it is
supposed to. This is broken for the 10_4 style NSNumberFormatter in
Tiger (10.4.x). It is fixed in Leopard, and works correctly (the way
he expects) for 10_0 style number formatters in Tiger. This can be
worked around in Tiger by subclassing and overriding the string<-
>number methods to look for the zero cases first and have different
behavior, calling super when not zero.
It is not intended that NSNumberFormatter has a way to change the
Unicode digits which are used. (The default behavior of the
underlying system should apply.)
Chris Kane
Cocoa Frameworks, Apple
On Aug 3, 2007, at 7:22 PM, Deborah Goldsmith wrote:
This doesn't do what you think it does. It sets the *character*
used for zero. The characters for 1-9 are derived by adding 1-9 to
that character. When you set it to " - ", it takes the first
character of that string (space, U+0020) as zero. One is the that
plus one, or U+0021 EXCLAMATION MARK.
This is used for non-ASCII digit support, which is important in
languages that don't use the Latin alphabet. Examples include
Arabic, Persian, and Hindi.
If you want to substitute a string for zero, you're going to have
to special-case that yourself.
Deborah Goldsmith
Internationalization, Unicode Liaison
Apple Inc.
email@hidden
On Jul 30, 2007, at 1:14 PM, Marcus S. Zarra wrote:
Unfortunately, there is very little documentation over this method
call. It was my guess that you can define how to display zero (as
opposed to a positive or negative number) when the formatter
encounters one. However, on testing it is yielding results that
are very odd.
My end goal is to get a zero value to be displayed as a - similar
to the way that Excel does when the column is defined as
accounting. However, the results are odd.
NSNumberFormatter *currencyNumberFormatter = [[NSNumberFormatter
alloc] init];
[currencyNumberFormatter
setFormatterBehavior:NSNumberFormatterBehavior10_4];
[currencyNumberFormatter
setNumberStyle:NSNumberFormatterCurrencyStyle];
[currencyNumberFormatter setAlwaysShowsDecimalSeparator:YES];
[currencyNumberFormatter setZeroSymbol:@" - "];
NSLog(@"Zero: %@", [currencyNumberFormatter stringFromNumber:
[NSDecimalNumber zero]]);
NSLog(@"One: %@", [currencyNumberFormatter stringFromNumber:
[NSDecimalNumber one]]);
NSLog(@"Odd: %@", [currencyNumberFormatter stringFromNumber:
[NSNumber numberWithDouble:2.99]]);
[currencyNumberFormatter setZeroSymbol:@" - "];
NSLog(@"Zero: %@", [currencyNumberFormatter stringFromNumber:
[NSDecimalNumber zero]]);
NSLog(@"One: %@", [currencyNumberFormatter stringFromNumber:
[NSDecimalNumber one]]);
NSLog(@"Odd: %@", [currencyNumberFormatter stringFromNumber:
[NSNumber numberWithDouble:2.99]]);
Results:
2007-07-30 14:08:17.482 Tester[20891] Zero: 0.00
2007-07-30 14:08:17.482 Tester[20891] One: $1.00
2007-07-30 14:08:17.482 Tester[20891] Odd: $2.99
2007-07-30 14:08:17.482 Tester[20891] Zero: -
2007-07-30 14:08:17.482 Tester[20891] One: $!.
2007-07-30 14:08:17.482 Tester[20891] Odd: $".))
The docs hint at putting literal data in single quotes but that
has no effect.
Other than subclassing NSNumberFormatter, does anyone know of any
other way to get zero to be displayed as a -?
Also, this seems like buggy behavior to me in the 10.4
formatters. Does this make sense to anyone else why it would
format like this or should I file a radar?
Thanks for any help.
Marcus S. Zarra
Zarra Studios LLC
Simply Elegant Software for OS X
www.zarrastudios.com
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden