Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSNumberFormatter -setZeroSymbol:



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.