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
Michael Jones
Python Development Techdegree Graduate 38,554 PointsAssigning a Double to a TextField in Swift.
Hi All,
I would like to take a Double value and place it into a UITextField. I understand I need to convert this Double into a String before doing that.
How do I do that? Is this possible?
Hope someone can help.
Thanks.
2 Answers
Muhammad Nadat
Full Stack JavaScript Techdegree Student 27,165 PointsYou can try something like this
let str = NSString(format: ".2lf", 3.1456)
try the following link to get more of an understanding of the format specifiers xcdoc://?url=developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#
Michael Jones
Python Development Techdegree Graduate 38,554 PointsThanks for your help. That makes sense.
My code would be this -
var revenueString = String(format: "%f", revenueFloat)
Now the 'revenueString' variable is a string value of the 'revenueFloat'. But I want the 'revenueString' to be displayed in a UITextField.
What is the syntax for that?
Hope you can help me.
Thanks,
Michael Jones
Python Development Techdegree Graduate 38,554 PointsWhey!! Figured it out. Thanks for your help.