Doubles

When returning a double from a calculation, where the hundredths place is a zero (such as 155.50), how do I get Swift to return 155.50 to the console instead of 155.5?

If you’re just looking to display the double as a string with the hundredths place (like when displaying currency, for example), you can format the string itself.

import Foundation

let totalAmount = 155.5
let formatted = String(format: "Total Amount: %.2f", totalAmount)

print(formatted) // prints Total Amount: 155.50

Here’s a link for a bunch of other ways to format and/or round floats as well:
https://stackoverflow.com/a/38036978