[英]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.