Post

Swift(스위프트): 숫자를 세자리수씩 끊고 콤마(,) 넣기

스위프트에서 숫자를 세자리수 단위로 끊은 뒤 콤마를 넣고 싶다면 아래 코드를 함수로 만들어 사용하면 됩니다.

1
2
3
4
5
6
func numberFormatter(number: Int) -> String {
    let numberFormatter = NumberFormatter()
    numberFormatter.numberStyle = .decimal
    
    return numberFormatter.string(from: NSNumber(value: number))!
}

 

출처: https://kka7.tistory.com/44

This post is licensed under CC BY 4.0 by the author.