I am facing a problem where I am not getting values of decimal places here is the code that I used to run in Swift Playground
print(100/1000)
print(Float(100/1000))
Expected Output :
0.10
0.10
Actual Output:
0
0.0
I am facing a problem where I am not getting values of decimal places here is the code that I used to run in Swift Playground
print(100/1000)
print(Float(100/1000))
Expected Output :
0.10
0.10
Actual Output:
0
0.0
Because of this:
let variable = 100/1000
print(type(of: variable))
// prints Int
Just do the following:
print(100.0 / 1000.0)
print(Float(100) / Float(1000))
So in order to get a floating point result you need to divide floating point numbers instead of two integers