我需要计算一下Kotlin 的百分比.我试过了,但没有得到正确的答案:
var percentage = (count/totalCount) * 100
it.toast("Percentage: $percentage")
Kotlin 语的正确句法是什么?
我需要计算一下Kotlin 的百分比.我试过了,但没有得到正确的答案:
var percentage = (count/totalCount) * 100
it.toast("Percentage: $percentage")
Kotlin 语的正确句法是什么?
Most likely, you're struggling with the fact that applying the division operator on two integers will result in an integer division being performed, yielding an integer result.
诀窍是将其中一个操作数提升为浮点类型:
var percentage = (count.toDouble() / totalCount) * 100