[英]how do I prevent numbers from going to Scientific Notations in my TextView?
我正在做一个计算器。 当我添加太多字符时,显示会自动获取这个科学计数法。
我该如何防止这种情况?
if ((answer == null)) {
answer = 0.0
} else {
answer = (answer * 10) + digit
}
answerEditText.setText(checkLast2Digits(answer.toDouble().toString()))
}
// removes the .0 from the end of the string
private fun checkLast2Digits(answerText: String): String {
val checkLast2Digits = answerText.takeLast(2)
if (checkLast2Digits.equals(".0")) {
return answerText.toString().take(answerText.toString().length - 2)
} else {
return answerText.toString()
}
}
您可以使用.toBigDecimal().toPlainString()
来避免科学记数法。 这也会删除小数点后的尾随零,因此您也不需要其他 function。
answerEditText.setText(answer.toBigDecimal().toPlainString())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.