如何从 Kotlin 中的数字中删除小数部分?

Why*_*sMe 2 android kotlin

我正在将OpenWeatherMapsAPI 用于天气应用程序,但它在某些城市显示小数,如何从中删除小数部分?

override fun onPostExecute(result: String?) {
            super.onPostExecute(result)
            try {
                val jsonObj = JSONObject(result)
                val main = jsonObj.getJSONObject("main")
                val temp = main.getString("temp")+"°C"
                findViewById<TextView>(R.id.temp).text = temp
Run Code Online (Sandbox Code Playgroud)

for*_*pas 8

如果您想要点之前的所有内容,则有substringBefore()

val temp = main.getString("temp").substringBefore(".") + "°C"
Run Code Online (Sandbox Code Playgroud)