Before i updated xCode 6, I had no problems casting a double to a string bur now it gives me error
var a: Double = 1.5
var b: String = String(a)
It gives me the error message "double is not convertible to string". Is there any other way to do it?
In addition to @Zaph answer, you can create
extension:
Usage:
This function will let you specify the number of decimal places to show:
Usage:
update Xcode 7.1 • Swift 2.1:
Now Double is also convertible to String so you can simply use it as you wish:
Xcode 8.3.2 • Swift 3.1:
for fixed number of fraction digits you can also extend Double:
If you need more control over your number format (minimum and maximum fraction digits and rounding mode) you can use NumberFormatter:
Swift 4: Use following code
This works for me. You may have a try
to make anything a string in swift except maybe enum values simply do what you do in the println() method
for example: