Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Andrew Vernon
1,480 PointsStormy - Percent instead of Double
I'm not sure if this is the best way to do this... And I am definitely still learning. But I put together a quick bit of code to change the humidity and chance of rain figures in Stormy from Doubles into percentages.
I'm taking the currentWeather measurements and multiplying them by 100 and then expressing them as Int. It seems to work. I had looking into trying to write a NSNumberFormater type of thing, but that seemed a little over my head. Then all I did was update the UILabels for these fields to show the new percent values + a percent symbol.
What do you all think?
'''
let precipStarterPercent = (currentWeather.precipProbability * 100)
let precipPercent = Int(precipStarterPercent)
// println(currentWeather.precipProbability)
// println(precipPercent)
let humidityStarterPercent = (currentWeather.humidity * 100)
let humidityPercent = Int(humidityStarterPercent)
// println(currentWeather.humidity)
// println(humidityPercent)
'''
Here's how I put the new percentages into my existing labels with the percent symbol.
'''self.humidityLabel.text = "\(humidityPercent)%"
self.precipitationLabel.text = "\(precipPercent)%"'''
Andrew Vernon
1,480 PointsAndrew Vernon
1,480 PointsI guess this would be a more concise way of doing the percent code
'''
'''