androidandroid-studiokotlin

Android Studio Kotlin - How to display 2 digit number in text?


On creating a timer In Android Studio Kotlin.

I'd like to display the time value as it's 2 digit number like '01:04:07'.

Please see the below.

enter image description here

enter image description here

At this point, how do I change the code?


Solution

  • You can use DecimalFormat as below:

      val f: NumberFormat = DecimalFormat("00")
      timerDisplay.text = "${f.format(lapshours)}:${f.format(lapsMin)}:${f.format(lapsSec)}"