
This week I got tripped-up by what I reckon is a rookie mistake.
Let's say we're building a clock face with just the hours. We'd use a maximum of 12 to represent each hour. 3 would point to 3 on the clock face, 7 to 7, etc
I was trying to work out how many degrees of a circular gauge view to fill when given twoIntegers
representing its current and maximum possible values.
What I did wrong
letcurrent:Int=6// where the hour hand should point to...letmax:Int=12letdegreesToFill:Double=Double(current/max)*360.0
How I fixed it:
letdegreesToFill:Double=(Double(current)/Double(max))*360.0
The mistake:
It seems that attempting to cast the result of the initial division returns 0 rather than the result as aDouble
, as expected.
The way which worked was to cast eachInteger
separately, then divide them before multiplying by the maximum number of degrees in the circle.
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse