Created
February 6, 2016 14:28
-
-
Save carlynorama/378a66dbe0e7f383e1a3 to your computer and use it in GitHub Desktop.
Learning how to print strings in Swift using the C++ stdout printf format specifiers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Working with numbers in strings | |
| import UIKit | |
| var str = "Hello, playground" | |
| let myInt:Int = 7; | |
| let myDouble:Double = 8.4; | |
| // basic | |
| print("The result of \(myInt) multiplied by \(myDouble) is \(Double(myInt) * myDouble)"); | |
| // formating fancy | |
| let result:Double = myDouble * Double(myInt); | |
| //http://www.cplusplus.com/reference/cstdio/printf/ | |
| print(String(format: "The result of %4.4d multiplied by %0.2f is %g", myInt, myDouble, result)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment