Hey swift forums, I'm getting an error and am not sure how to fix it. Any help would be greatly appreciated.
Hi!
Swift tries to be safe, so operations like "/" and "*" need to be applied between instances of matching types
You can try doing String(Double(previousNumber) / Double(numberOnScreen))
to make sure that both types are the same the operation / is defined on them
That seemed to work but I received another error, "Expected ')' in expression list"
this seems a little too safe in my opinion. Sorry if I seem irritating for not knowing this, I assume it's really simple. Again any help greatly appreciated.
That seemed to work but I received another error, "Expected ')' in expression list"
this seems a little too safe in my opinion. Sorry if I seem irritating for not knowing this, I assume it's really simple.03%20AM|690x431
You missed a closing parenthesis at the end.
thanks
Also numberOnScreen
is already Double
. So you don't need to do Double(numberOnScreen)
, just numberOnScreen
okay I changed the (numberOnScreen), I don't see exactly where I missed the parenthesis at the end. Also I got a new error...
Could you recompile the proj, they seems to be old error.
Also, do you want "decimal point" in your computation?
That is, should 3/2
be 1
or 1.5
?
And do you permit 3.2 + 5.4
?
Other folks have answered your direct question, but I want to make a bigger picture comment. You have code like his:
label.text = String(xxx)
where xxx
is a Double
. Presumably label
is a UILabel
, in which case I recommend that you check out NumberFormatter
. You’re currently relying on Swift’s default conversion from Double
to String
, and that’s not appropriate for user-visible content. NumberFormatter
will take care of complexities like:
-
Whether to use point or comma for the decimal separator
-
The separator and grouping of digits in large numbers
-
Folks who prefer other digit representations (for example, Eastern Arabic digits)
ps When you post code, it’s better to post it as text (formatted as a code block) rather than a screen shot, because that way folks can copy snippets from your code.
Share and Enjoy
Quinn “The Eskimo!” @ DTS @ Apple