0
1

More than 3 years have passed since last update.

文字列から数値に変えてフォーマットする

Posted at

数値を文字列にするパターンはあったのに、文字列から数値に変えてフォーマットするパターンがなかったので作成します。

let a = Int(文字列の変数名etc)
String(format: "%05d", _a))

やることは2つ

文字列をInt型に変換
Intでフォーマット

できないって場合

型を調べてください。
オプショナル型ならif letのなかでやるとうまくいくと思います。

let a = Int(文字列の変数名etc)
if let _a = a{
String(format: "%05d", _a))
}

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