According to the comment description for Double.rem
:
/**
* Calculates the remainder of truncating division of this value by the other value.
*
* The result is either zero or has the same sign as the _dividend_ and has the absolute value less than the absolute value of the divisor.
*/
@SinceKotlin("1.1")
public operator fun rem(other: Double): Double
However, when I run the following code:
fun main() {
println(10.0 % 0.2)
}
It outputs 0.19999999999999946
when it should output 0.0
. How do I run an accurate rem
for doubles?
Note: try it yourself here