Friday, January 23, 2015

Swift Tip - Using format specifier

In Swift, if you want to apply a format specifier to a double or float value, you can use the String class's format:arguments: method, like this:

            var temperature = 1.235567
            var temperatureStr = String(format:"%.2f", temperature)
            // temperatureStr is now 1.24


No comments: