![[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)
![[Laravel][mailtrap]Expected response code 354 but got code ''550'', with message ''550 5.7.0 Requested action not taken: too many emails per second ''エラーについて](https://www.yukiiworks.com/wp-content/uploads/2019/05/laravel-150x150.png)
![[超簡単!]情報処理試験のための論理回路の覚え方](https://www.yukiiworks.com/wp-content/uploads/2019/03/code1211IMGL1494_TP_V4-150x150.jpg)
![[Kotlin][Android]BottomNavigationViewとViewPagerを用いたタブ遷移の実装](https://www.yukiiworks.com/wp-content/uploads/2019/04/kotlin-150x150.png)
![[iOS13][Process] kill() returned unexpected error 1エラーについて](https://www.yukiiworks.com/wp-content/uploads/2019/09/Xcode-150x150.png)
![[Swift]unrecognized selector sent to instance エラーについて](https://www.yukiiworks.com/wp-content/uploads/2019/04/swift-150x150.png)
![[Android]Error while executing: am start -n XXX.....エラーについて](https://www.yukiiworks.com/wp-content/uploads/2019/10/android-studio-e1585186990750-150x150.jpg)
![[javascript]ブラウザの戻るボタンで戻ってきた時になんらかの処理をする方法](https://www.yukiiworks.com/wp-content/uploads/2019/05/javascript-150x150.png)

