roundToLong

Platform and version requirements: JVM (1.2), JS (1.2), Native (1.2)
fun Double.roundToLong(): Long

Rounds this Double value to the nearest integer and converts the result to Long. Ties are rounded towards positive infinity.

Special cases:

  • x.roundToLong() == Long.MAX_VALUE when x > Long.MAX_VALUE
  • x.roundToLong() == Long.MIN_VALUE when x < Long.MIN_VALUE

Exceptions

IllegalArgumentException - when this value is NaN

Platform and version requirements: JVM (1.2), JS (1.2), Native (1.2)
fun Float.roundToLong(): Long

Rounds this Float value to the nearest integer and converts the result to Long. Ties are rounded towards positive infinity.

Special cases:

  • x.roundToLong() == Long.MAX_VALUE when x > Long.MAX_VALUE
  • x.roundToLong() == Long.MIN_VALUE when x < Long.MIN_VALUE

Exceptions

IllegalArgumentException - when this value is NaN

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.math/round-to-long.html