FeReTu FeReTu - 2 years ago 107
iOS Question

Int value with a dot minus an Int

I want to hear if it is possible to minus two numbers, when the one value contains a (.) at the end of the number.

I have a value like this:

var numberOne: String = "21."
print(Int(numberOne) - 1)

That is not possible, it does not work. So how can I do that?

Answer Source

No that is not possible because the conversion to Int(numberOne) will fail because of the ..

Double/Float will work:

var numberOne: String = "21."
print(Double(numberOne)! - 1) // 20.0
print(Float(numberOne)! - 1) // 20.0
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download