NSNumberFormatter -setZeroSymbol:
NSNumberFormatter -setZeroSymbol:
- Subject: NSNumberFormatter -setZeroSymbol:
- From: "Marcus S. Zarra" <email@hidden>
- Date: Mon, 30 Jul 2007 14:14:44 -0600
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
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
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