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

1 Answer

0 votes
val f = 1376.780152

val s = f.toString

val pointPos = s.indexOf('.')

println(s.substring(pointPos + 1, pointPos + 3))



   
/*
           
run:
     
78
       
*/



 



answered Sep 18, 2024 by avibootz
...