How to get the first two digits after the decimal point of a float number in Kotin

1 Answer

0 votes
class GetTheFirstTwoDigitsAfterTheDecimalPoint_Kotlin {
    companion object {
        @JvmStatic
        fun main(args: Array<String>) {
            val f = 3486.716052
            val s = f.toString()
            val pointPos = s.indexOf('.')
            
            println(s.substring(pointPos + 1, pointPos + 3))
        }
    }
}



/*
run:
  
71
  
*/

 



answered Oct 27, 2024 by avibootz
...