https://kotlinlang.org logo
Title
c

Christian Janev

07/09/2020, 11:10 PM
toBePercent = (toBePercent.toFloat() / 100).toString()
I have this line of code and whenever I make toBePercent into 5 it converts it to "0.05" (good) but whenever I make toBePercent into 10 or above it outputs "0.0"
d

Daniel Medeiros

07/09/2020, 11:23 PM
Maybe try:
toDouble
or use 100.0
c

Christian Janev

07/09/2020, 11:25 PM
I tried toDouble and 100.0 doesn't work
d

deactivateduser

07/09/2020, 11:36 PM
hrm, you have the sample code? it works fine here https://pl.kotl.in/crYCWYv6B
c

Christian Janev

07/09/2020, 11:39 PM
Maybe it's since I'm using android studio?
percentBtn.setOnClickListener {
            var toBePercent = text.text.toString().last().toString()
            toBePercent = (toBePercent.toFloat() / 100.00).toString()
            text.text = toBePercent
        }
d

deactivateduser

07/09/2020, 11:41 PM
var toBePercent = text.text.toString().last().toString()
you seem to be only taking the last digit here.... is that by design?
c

Christian Janev

07/09/2020, 11:41 PM
Just saw tjat
It works now
d

deactivateduser

07/09/2020, 11:42 PM
👍