![[Kotlin]0パディングした文字列を返すExtension](https://www.yukiiworks.com/wp-content/uploads/2019/04/kotlin.png)
はじめに
KotlinにてInt型の数値を指定桁数でゼロパディングした文字列を返すExtensionを作成しました。
コード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /** * 指定桁数で0パディングした文字列を返す * @param length 桁数 * @return 0パディングした文字列 */ fun Int.zeroPadding(length: Int): String { var target = this.toString() val remaining = length - target.length if (remaining > 0) { for (i in 1..remaining) { target = "0${target}" } } return target } |
拡張として作成することでInt型の変数でどこでも使えます!
![[Flutter]Navigatorで2つ前の画面に戻る方法](https://www.yukiiworks.com/wp-content/uploads/2020/08/flutter-300x144.png)
![[iOS13]ERROR ITMS-90785: “UIUserInterfaceStyle can’t be ‘light’. It can only be ‘Light’, ‘Dark’, or ‘Automatic’.エラーについて](https://www.yukiiworks.com/wp-content/uploads/2019/09/Xcode-150x150.png)

![[Google Play Console]アップロードできませんでした Android App Bundle は署名されていません。エラーについて](https://www.yukiiworks.com/wp-content/uploads/2019/06/google-play-150x150.jpg)
![[Laravel]APIのPUTメソッドにてFormRequestから値が取れない問題の対処方法](https://www.yukiiworks.com/wp-content/uploads/2019/05/laravel-150x150.png)
![[Android]Error while executing: am start -n XXX.....エラーについて](https://www.yukiiworks.com/wp-content/uploads/2019/10/android-studio-e1585186990750-150x150.jpg)
![[超簡単!]情報処理試験のための論理回路の覚え方](https://www.yukiiworks.com/wp-content/uploads/2019/03/code1211IMGL1494_TP_V4-150x150.jpg)

