Home > Net >  trying to use Float.parseFloat() in android but my IDE not recognizing parseFloat
trying to use Float.parseFloat() in android but my IDE not recognizing parseFloat

Time:06-08

Im trying to set rating in rating bar while the API service returns a sting for rating field. couldn't find any way to use it directly in xml using databinding so I tried binding adapter and surprisingly the parseFloat in Float.parseFloat() is not recognizing by my IDE. I have tried this piece of code in other part of project like fragments but nothing happens. Thanks for any idea and suggestion.

CodePudding user response:

To convert string to float use toFloatOrNull(), this will convert string to float

var string = "5" 
var floatNumber = string.toFloatOrNull()
Log.e(TAG, " string.toFloatOrNull() $floatNumber")

You can set this float value in rating bar

  • Related