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

前端 未结 7 1357
鱼传尺愫
鱼传尺愫 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];
    

提交回复
热议问题