I have a function to convert Double
values to String
, and add a variable number (from 0 to 3) of trailing zeroes at the end.
In this function, I can do this:
var string: String = ""
switch digits {
case 0: string = String(format:"%0.0f", doubleValue)
case 1: string = String(format:"%0.1f", doubleValue)
case 2: string = String(format:"%0.2f", doubleValue)
default: string = String(format:"%0.3f", doubleValue)
}
I would like to have a formatting option like:
let string = String(format:"%0.nf", numberOfDigits, doubleValue)
Where we can specify the number of digits (n) after the decimal point with a variable (numberOfDigits). I know that the variables should be the values to include in the String, and not a variable of the formatting enunciate..
Is there a way to do it?
Rgds... e