I have a TextEdit that has the input type of numberDecimal
and I executes some code with inputted number
when I enter a whole number it works fine but when I enter a number with a decimal point the app completely restarts
So how would I make it work with a decimal number?
if you do end up helping me thank you in advanced
KT file
class f_to_c : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.f_to_c)
val actionBar = supportActionBar
val calculate = findViewById<Button>(R.id.calculate)
val tempEntered = findViewById<TextView>(R.id.tempEntered)
val result = findViewById<TextView>(R.id.result)
val temp = findViewById<EditText>(R.id.temp)
if (actionBar != null){
actionBar.title = "Fahrenheit To Celsius"
actionBar.setDisplayHomeAsUpEnabled(true)
}
calculate.setOnClickListener {
var x = Integer.parseInt(temp.getText().toString()).toString().toInt()
tempEntered.text = x.toDouble().toString()
result.text = ((x-32).toFloat()*5/9).toString()
}
}
}