1

I have a slider, bind it with text field. It is possible automatically transform value to this format: Example 01 02 03 04 05 06 .. 13 14 15 ..? Thanks!

Nikolai Nagornyi
  • 1,312
  • 2
  • 11
  • 26

1 Answers1

2

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.

Community
  • 1
  • 1
John Sauer
  • 4,411
  • 1
  • 25
  • 33