How to get the first digit after the decimal point of a float number in Scala

1 Answer

0 votes
object Main {
  def main(args: Array[String]): Unit = {
    val f = 983.6571f
    
    val n = (math.floor(math.abs(f) * 10).toInt) % 10
    
    println(n)
  }
}
 
 
    
/*
run:
    
6
    
*/

 



answered Oct 30, 2024 by avibootz
...