How can I pad an integer on the left with zeros?

前端 未结 7 1359
鱼传尺愫
鱼传尺愫 2020-12-09 07:18

I have the following variable:

NSNumber *consumption = [dict objectForKey:@\"con\"];

Which returns 42. How can I pad this number to 10 dig

相关标签:
7条回答
  • 2020-12-09 08:24

    with variable num_digits

    NSString* format =[NSString stringWithFormat:@"%%0%zdzd", num_digits];
    NSString *theString = [NSString stringWithFormat:format, 42];
    
    0 讨论(0)
提交回复
热议问题