swift format double code example
Example 1: format decimal place swift
let tip: Double = 15.2847320
let tipText: String = String(format: "%.2f", tip)
// %.2f for two decimal places
Example 2: how do i get a string from a float swift to 1 decimal swift
let someFloat: Float = 3.14159
let floatToString: String = String(format: "%.01f", someFloat)
// floatToString => 3.14