Skip to content Skip to sidebar Skip to footer

Drop Un-needed Decimal ".0"

I'm making a simple calculator and I am having an issue with it showing a decimal on what I want to just be a whole number. For example, if the entered expression is '50 + 50' the

Solution 1:

You can use removeSuffix:

funmain() {
    println(100.5.toString().removeSuffix(".0"))
    println(100.0.toString().removeSuffix(".0"))
}

Output:

100.5
100

Post a Comment for "Drop Un-needed Decimal ".0""