How to format an integer with zero-padding in Swift

1 Answer

0 votes
import Foundation

let number = 319

// Format with leading zeros (6 digits total)
let formatted = String(format: "%06d", number)

print(formatted)



/*
run:

000319

*/

 



answered Jun 19, 2025 by avibootz

Related questions

...