Inga Codreanu
Inga Codreanu

Reputation: 21

error: could not find an overload for'init'that accepts the supplied arguments double (swift)

I have some problems with this error,I'm a beginner I will be very happy if you help me I try more variants but it didn't work

var x:Double = 0 


@IBAction func digitals(sender: UIButton)
{

    println("Cifra\(sender.tag)")
    if enterFlag == 1 {

        x = 0
        enterFlag = 0
    }


    if decimalPoint == 0
    {
        x = x * 10 + Double(sender.tag)

        self.result.text = " " + String(Int64(x))
    }
    else {
        x = x + Double(sender.tag)/pow(10, Double(power))
        power++
        self.result.text = String(x)  ===> error

    }


}

thank you very much for your advice ! :)

Upvotes: 1

Views: 441

Answers (2)

codester
codester

Reputation: 37189

There is no intializer to convert Double to String but You can convert Double to String by

self.result.text = "\(x)" 

You can use this way to convert any basic datatype to String

Upvotes: 2

derdida
derdida

Reputation: 14904

You can not convert a Double to a String.

You could use:

self.result.text = NSString(format: "%.2f", x)

Upvotes: 0

Related Questions