I need to transfer the double variable to the localization file, if I write %d I can only pass int, but I need to pass the double
Asked
Active
Viewed 125 times
-1
-
3Does this answer your question? [Precision String Format Specifier In Swift](https://stackoverflow.com/questions/24051314/precision-string-format-specifier-in-swift) – inokey Apr 08 '20 at 06:17
1 Answers
0
You can pass the double with format string %f
. To restrict the number of digits after the decimal point you can format is like this %0.2f
. This will allow only 2 digits after the decimal point.
Sample Code:
let num = 10.5
let outputStr = String(format:"I am printing %0.1f", arguments:[num])
print(outputStr)