1

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?

Hamish
  • 78,605
  • 19
  • 187
  • 280
Glatteisen
  • 163
  • 1
  • 3
  • 11

1 Answers1

5

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.

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223