Title
l

liminal

11/28/2018, 3:39 AM
how would i check if a float number has any non-zero decimal places 1f vs 1.2f
h

hudsonb

11/28/2018, 3:48 AM
mod it by 1
fun main(args: Array<String>) {
    val a = 3f
    val b = 3.14f
    println(a % 1 == 0f)
    println(b % 1 == 0f)
}
Would print the following:
true
false
So something like
if(foo % 1 != 0f)
You could also turn it into an extension functions/vals:
inline fun Float.isWhole() = this % 1 == 0f
inline fun Float.isNotWhole() = !isWhole()
or w/e you'd want to call them
l

liminal

11/28/2018, 4:04 AM
thanks a lot, @hudsonb
n

nfrankel

11/28/2018, 7:15 AM
nice trick!