• 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
Zero-padding an NSNumberFormatter
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Zero-padding an NSNumberFormatter
      • From: Chris Kane <email@hidden>
    • Re: Zero-padding an NSNumberFormatter
      • From: Keary Suska <email@hidden>
  • Prev by Date: nodesForXPath almost always returns no objects
  • Next by Date: TextStorage should read html anchors
  • Previous by thread: Re: nodesForXPath - is this correct behaviour?
  • Next by thread: Re: Zero-padding an NSNumberFormatter
  • Index(es):
    • Date
    • Thread