Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to write a formula in Kotlin

I’m trying to write a formula where the shorter the distance, the more points you get, the farther the distance, the less points

    fun raiting(distance: Float): Int {
    var rating = 1000
    var maxDistance = 11750F
    
    rating = if (distance > maxDistance) {
        0
    } else{
        ..
    }


    return rating
}

The question is how to write such a formula? Or tell me which formula to use

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can simply calculate percentage of distance from max distance where 0 means 100% and maxDistance means 0%:

fun raiting(distance: Float): Int {
    var maxDistance = 11750F
    
    rating = 100 - (distance * 100 / maxDistance)


    return toInt(rating)
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading