When I try this:

let progress: CGFloat = CGFloat(2 / 3)
print(progress)

The console returns 0 but the result is 0,66666666667, not 0.... Why is that happening?

When I try:

let progress: CGFloat = CGFloat(10 / 3) 
print(progress)

It returns 3.0, is that the way how CGFloat works? Is there no way to get comma numbers with CGFLoat?

1  
You're doing integer division, not floating point. – Sami Kuhmonen 2 hours ago

1 Answer 1

If you leave out converting, this will work perfectly.

let progress: CGFloat = 2 / 3
print(progress) //0.666666666666667

The reason why this does not work with explicit converting is beause Swift treats a whole number as an Int if it's without context.

That's exactly what is happening inside converting brackets.