【Xcode/Swift】文字列を3桁区切りにカンマを入れて表示する方法

コード

func getComma(_ num: Int) -> String {
    let formatter = NumberFormatter()
    formatter.numberStyle = .decimal
    formatter.groupingSeparator = ","
    formatter.groupingSize = 3
    let number = "¥\(formatter.string(from: NSNumber(value: num)) ?? "")"
    
    return number
}