![[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)
![[Android]WebViewでスクロールをバウンドさせない方法](https://www.yukiiworks.com/wp-content/uploads/2019/10/android-studio-e1585186990750-150x150.jpg)
![[Laravel]指定のレコードだけは先頭にして抽出する方法](https://www.yukiiworks.com/wp-content/uploads/2019/05/laravel-150x150.png)
![[Kotlin][Android]スプラッシュ画面の作成](https://www.yukiiworks.com/wp-content/uploads/2019/04/kotlin-150x150.png)
![[DB2]ロード後に表スペースにアクセスできない問題について](https://www.yukiiworks.com/wp-content/uploads/2019/03/code1211IMGL1494_TP_V4-150x150.jpg)
![[Swift]WKWebViewでピンチイン、アウトを無効にする方法](https://www.yukiiworks.com/wp-content/uploads/2019/04/swift-150x150.png)

