The following code:
import Foundation // required for String(format: _, _)
print(String(format: "a float number: %.2f", 1.0321))
will output:
a float number: 1.03
More Related Contents:
- type 'UIViewController' has no member updateTimer
- Is Swift Pass By Value or Pass By Reference
- #ifdef replacement in the Swift language
- Error-Handling in Swift-Language
- What’s the cleanest way of applying map() to a dictionary in Swift?
- Segue and Button programmatically swift
- Swift – Resolving a math operation in a string
- Swift variable decorations with “?” (question mark) and “!” (exclamation mark)
- Formatting input for currency with NSNumberFormatter in Swift
- Swift protocol with “where Self” clause
- How do I store a value of type Class in a Dictionary of type [String:Class] in Swift?
- Unexpected Non-Void Return Value In Void Function (Swift 2.0)
- Swift 3 for loop with increment
- What does “@UIApplicationMain” mean?
- Call a method from a String in Swift
- Express for loops in swift with dynamic range
- Iterate through files in a folder and its subfolders using Swift’s FileManager
- Extend array types using where clause in Swift
- How change background color if using NavigationView in SwiftUI?
- Filter non-digits from string
- How to remove the left and right Padding of a List in SwiftUI?
- PNG/JPEG representation from CIImage always returns nil
- How do I encode enum using NSCoder in swift?
- How do I see which version of Swift I’m using?
- try, try! & try? what’s the difference, and when to use each?
- Swift 4 Decodable – Dictionary with enum as key
- Get Description of Emoji Character
- Self in init params
- How to convert a binary to decimal in Swift?
- Remove element from collection during iteration with forEach