Hey I am working in android kotlin. I am getting double value in the form of string from server. I am converting that value in Int and checking that value is not null using toIntOrNull(). But I am getting 0 all the time.
Value coming from server
"value": "79.00"
My Data class
import android.os.Parcelable
import kotlinx.android.parcel.Parcelize
@Parcelize
data class Detail(
val value: String? = null,
) : Parcelable {
val valueInDouble by lazy {
value?.toDoubleOrNull() ?: Double.NaN
}
val valueInInt by lazy {
value?.toIntOrNull() ?: 0
}
}
whenever I print the value of valueInInt in console it returns 0. I know that 0 is coming because of toIntOrNull() but my value is coming from server which is not null. But I don't understand why this is happening. Can someone guide me please?
Expected Output
79
Actual Output
0
79.00