Zero-padding an NSNumberFormatter
Zero-padding an NSNumberFormatter
- Subject: Zero-padding an NSNumberFormatter
- From: Nick Zitzmann <email@hidden>
- Date: Mon, 8 Jan 2007 18:45:32 -0700
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