toDouble
Returns the value of this duration expressed as a Double number of the specified unit.
The operation may involve rounding when the result cannot be represented exactly with a Double number.
An infinite duration value is converted either to Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY depending on its sign.
Since Kotlin
1.6Samples
import kotlin.test.*
import kotlin.time.*
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.microseconds
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.nanoseconds
import kotlin.time.Duration.Companion.seconds
fun main() {
//sampleStart
println(2900.milliseconds.toDouble(DurationUnit.SECONDS)) // 2.9
println(1.seconds.toDouble(DurationUnit.MINUTES)) // 0.016666666666666666
println(Duration.INFINITE.toDouble(DurationUnit.SECONDS)) // Infinity
//sampleEnd
}