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