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

前端 未结 7 1444
鱼传尺愫
鱼传尺愫 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:17

    You can do pretty much any number formatting you would ever want with NSNumberFormatter. In this case I think you would want to use the setFormatWidth: and setPaddingCharacter: functions.

提交回复
热议问题