Dates, Formatting, and Text
Formatted Numbers
Formatting can turn a numeric value into text with a chosen precision.
Choose decimal places
formatted_numbers.swift
import Foundation
let price =
let formatted = String(format: "%.2f", price)
let message = "price=\(formatted)"
print(message)
import Foundation
let price =
let formatted = String(format: "%.2f", price)
let message = "price=\(formatted)"
print(message)
import Foundation
let price =
let formatted = String(format: "%.2f", price)
let message = "price=\(formatted)"
print(message)
number formatting
`String(format:)` produces a string representation with a predictable number of decimal places.