Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

kotlin android studio Unable to figure out how to covert that text to double. Can somebody correct the code please?

kotlin android studio Unable to figure out how to covert that text to double. Can somebody correct the code please?

that code gives an error –

Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
public inline fun String.toDouble(): Double defined in kotlin.text
  package com.example.termoparacalculator

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import 
com.example.termoparacalculator.databinding.ActivityMainBinding 

class MainActivity : AppCompatActivity() {

private  lateinit var  binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    binding = ActivityMainBinding.inflate(layoutInflater)
    setContentView(binding.root)

    binding.button.setOnClickListener{
        val inp = binding.input.text.toDouble()
        val temp = 2.0609 * inp + 25.748
        binding.textView2.text = temp
    }

    }
}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Assuming input is an EditText you need to do toString first

binding.input.text.toString().toDouble()

then make temp a string too when setting since its a double

binding.textView2.text = temp.toString()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading