Anoop is right. Create an NSNumberFormatter, and setting its minimumIntegerDigits to 2 will add a leading zero to single-digit numbers.
// Create an NSNumberFormatter that will add a leading 0 to single-digit numbers.
NSNumberFormatter* leadingZeroNumberFormatter = [NSNumberFormatter new] ;
leadingZeroNumberFormatter.minimumIntegerDigits = 2 ;
// Attach the NSNumberFormatter to your NSTextField
textField.formatter = leadingZeroNumberFormatter ;
The above example will take 6.27
and return 06
. If you'd rather see the .27
, check out the fractionDigits
methods in the NSNumberFormatter class reference.