I am trying to reduce the amount of characters in a double. How Would I reduce this:
59.5220000
to
59.5
this in swift?
I am trying to reduce the amount of characters in a double. How Would I reduce this:
59.5220000
to
59.5
this in swift?
A double doesn't have characters. A string rendering of it does. Rather than using the standard String()
initializer (which is really only for development use, it's terrible for end-users), use NumberFormatter
.
perhaps use a formatted string?
let str = String(format: "%.2f", 59.5220000)