Home > Blockchain >  Rounding off the Float to highest
Rounding off the Float to highest

Time:05-25

I am using below code to round off the float result to an integer.

230.div(20.00).toFloat().roundToInt())

The above example gives me 11.5 roundng off to Int 12 but the same code is not rounding of 5.3 to 6

106.div(20.00).toFloat().roundToInt())

Is there any way to round off the float to highest i.e 5.3 to 6

CodePudding user response:

Use Math.ceil(5.3) to round it to 6. It will return Double then you can use toInt() on it. Like this:

val value = 106.div(20.00)
val finalValue = Math.ceil(value).toInt()
  • Related