I have converted a String
to an Int
by by using toInt()
. I then tried multiplying it by 0.01, but I get an error that says Could not find an overload for '*' that accepts the supplied argument.
Here is my code:
var str: Int = 0
var pennyCount = 0.00
str = pennyTextField.text.toInt()!
pennyCount = str * 0.01
From reading other posts it seems that the answer has to do with the type. For example if the type is set as an Integer then it gets a similar error. I have tried changing the type to an Int, but that doesn't seem to solve the problem.
I have also tried setting the type for 'str' and 'pennyCount' as Floats
and Doubles
and all combinations of Floats
, Doubles
, and Ints
. My guess is the the problem has to do with toInt()
function's conversion of a String
to an Integer
.
Could someone help clarify what the issue may be?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…