Skip to content

Instantly share code, notes, and snippets.

@carlynorama
Created February 6, 2016 14:28
Show Gist options
  • Select an option

  • Save carlynorama/378a66dbe0e7f383e1a3 to your computer and use it in GitHub Desktop.

Select an option

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
// 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