Re: Zero-padding an NSNumberFormatter
Re: Zero-padding an NSNumberFormatter
- Subject: Re: Zero-padding an NSNumberFormatter
- From: Chris Kane <email@hidden>
- Date: Mon, 22 Jan 2007 10:57:06 -0800
I saw this recently in another context. You are inadvertently running
into a bug in NSNumberFormatter in Tiger:
4553621 NSNumberFormatter returns garbage after setting zero symbol
by using the setFormat: method to set the zero symbol.
You'd get the results you want for negative and positive numbers by
using
[offsetFormatter setNegativeFormat:@"-####"];
[offsetFormatter setPositiveFormat:@"+####"];
instead of setFormat:, but you still wouldn't get the formatting you
wanted for zero. (I just prefer using # but 0 in the format would be
the same.) You'll get "0". That's another issue [ICU ignores the
"max/min digits" settings for 0 and the positive format isn't used for
0 either.].
This has been dealt with only post-Tiger at this point.
Chris Kane
Cocoa Frameworks, Apple
On Jan 8, 2007, at 5:45 PM, Nick Zitzmann wrote:
I've RTFM'd and STFA'd and still don't get something...
I want to create an NSNumberFormatter that shows time offsets, so
that a positive offset (like 700) becomes +0700, a negative offset
becomes -0700, etc. Here's what I'm trying:
NSNumberFormatter *offsetFormatter = [[[NSNumberFormatter alloc]
init] autorelease];
[offsetFormatter setFormatterBehavior:NSNumberFormatterBehavior10_4];
[offsetFormatter setFormat:@"+0000;+0000;-0000"];
[offsetFormatter setUsesGroupingSeparator:NO];
[offsetFormatter setAllowsFloats:NO];
[offsetFormatter setMaximumIntegerDigits:4];
[offsetFormatter setMinimumIntegerDigits:4];
[offsetFormatter setPaddingCharacter:@"0"];
But when I plug the number -700 into this, the resulting string is "-
+2++". I expected it to be "-0700". Not only is the hundredths-place
number wrong, but the zero-padding is replaced by plus-padding.
However, when I plug in 0 I get the expected result ("+0000").
What am I doing wrong and how do I fix this?
Nick Zitzmann
<http://www.chronosnet.com/>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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)
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