0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Swift金額をカンマ区切りでフォーマットする方法

Last updated at Posted at 2025-01-18

金額などで使用できる、カンマ区切りでフォーマットする方法です。

.swift

    func formatToCurrency(amount: Int) -> String {
        let numberFormatter = NumberFormatter()
        numberFormatter.numberStyle = .decimal // 小数点以下やカンマ区切りを指定
        numberFormatter.groupingSeparator = "," // カンマをグループセパレーターに設定
        return numberFormatter.string(from: NSNumber(value: amount)) ?? "0"
    }

簡単にカンマ区切りすることができました。

Simulator Screenshot - iPhone 16 Pro - 2025-01-19 at 08.31.21.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?