Ben Edwards08/17/2022, 5:56 PM
val purchasedTickets: Int = 10
val totalTickets: Int = 100
This is obviously going to truncate the numbers inside the brackets so the answer will be wrong but what is the correct way to handle this?
percentagePurchased = (purchasedTickets/ totalTickets) * 100
Ciaran Sloan08/17/2022, 6:13 PM
is this what you're looking for?
val purchasedTickets: Int = 10 val totalTickets: Int = 100 val percentagePurchased = (purchasedTickets.toFloat()/ totalTickets.toFloat()) * 100F
Ben Edwards08/17/2022, 6:16 PM
However, still testing.
percentagePurchased = (purchasedTickets.toFloat() / totaltickets) * 100
Ciaran Sloan08/17/2022, 6:20 PM
ephemient08/17/2022, 6:26 PM
val x = 50000000 x + 1 == x // false, of course x.toFloat() + 1f == x.toFloat() // true due to running out of precision
Ben Edwards08/17/2022, 6:33 PM
ephemient08/17/2022, 6:40 PM
Ben Edwards08/17/2022, 6:47 PM
Michael de Kaste08/18/2022, 9:33 AM