我正在将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)
如果您想要点之前的所有内容,则有substringBefore():
val temp = main.getString("temp").substringBefore(".") + "°C"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2906 次 |
| 最近记录: |