我的 中有此代码DestinationCreateActivity.kt 创建新数据,如何将文本转换为浮点数?
DestinationCreateActivity.kt
newDestination.amount = amount.text.toFloat()
这是我的 activity_destiny_create.xml
<EditText
android:id="@+id/amount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Amount"
android:imeOptions="actionUnspecified"/>
我的模型@Field("amount") amount: Float,
这是错误最佳答案
这里amount.text
不是 String
但它的CharSequence
.因此,您应该将其转换为 String
然后转换为 Float
:
amount.text.toString().toFloat()
关于android - 公共(public)内联乐趣 String.toFloat() : Float defined in kotlin. 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62874595/