Precision String Format Specifier In Swift

The following code:

import Foundation // required for String(format: _, _)

print(String(format: "a float number: %.2f", 1.0321))

will output:

a float number: 1.03

Leave a Comment