Mailing Lists: Apple Mailing Lists

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

Re: Padding Zeros...



On Oct 31, 2008, at 4:52 PM, Jean-Nicolas Jolivet wrote:

I'm having an interesting problem... I'm trying to format a number with padding zeros but I can't figure out how to do it in this particular situation.

I know I can use a formatted string with something like [stringWithFormat:@"%03d", 5], which would result in 005 but the problem in this particular case is that the number of padding zeros (3 in my example) is a variable defined by the user... (let's say it resides in an int variable named "int paddingZeros"....)

Is there an easy way I can pad a number with a variable amount of zeros?

I don't remember off-hand if this is supported by NSString, but printf and friends supports ("%0*d", paddingZeros, 5).


That is, put an asterisk in place of the field width and then supply it as an argument.

Cheers,
Ken

_______________________________________________

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
References: 
 >Padding Zeros... (From: Jean-Nicolas Jolivet <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.