将String转成数字类型, 如果转成成功就返回数字, 转换失败则返回null
函数 | 案例 | 结果 |
---|---|---|
int(): Int? | val i: Int? = “111”.int() | 111 |
long(): Long? | val i: Long? = “111”.long() | 111 |
double(): Double? | val i: Double? = “111.23”.double() | 111.23 |
float(): Float? | val i: Float? = “111.23”.float() | 111.23 |