I have followed a few other similar posts on here but despite following some tips I am still not getting the result I expect
I have two variables: TimeTaken and TimeGiven. Both are stored as Int values (representing seconds)
When I output the individual values they come out correctly as integers
Example
TimeTaken = 4 and TimeGiven = 10
I then have a function to get a percent as an integer from the value. I have seen different ways and here are two of them:
Option 1
private fun getPercent(timeTaken:Int,timeGiven:Int): Int {
return ((timeTaken.toDouble() / timeGiven)*100).roundToInt()
}
Option 2
private fun getPercent(timeTaken:Int,timeGiven:Int): Int {
return (timeTaken / timeGiven)*100
}
When I am calling this e.g.
getPercent(TimeTaken,TimeGiven)
I always get 0 as a return when I output the result to a textview
To see the value in my textview (until I can prove it working) I am simply doing this(where TIMETAKitm.text has already been initialised as a view);
TIMETAKitem.text = getPercent(TimeTaken,TimeGiven).toString()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…