• 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: NSNumberFormatter -setZeroSymbol:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNumberFormatter -setZeroSymbol:


  • Subject: Re: NSNumberFormatter -setZeroSymbol:
  • From: Deborah Goldsmith <email@hidden>
  • Date: Fri, 03 Aug 2007 19:22:20 -0700

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


  • Follow-Ups:
    • Re: NSNumberFormatter -setZeroSymbol:
      • From: Chris Kane <email@hidden>
  • Prev by Date: Catching events in an empty window.
  • Next by Date: Re: Quickest Drawing Method
  • Previous by thread: Re: Catching events in an empty window.
  • Next by thread: Re: NSNumberFormatter -setZeroSymbol:
  • Index(es):
    • Date
    • Thread