In Swift, you can use the round()
function from the Foundation
library to round a number to the nearest thousandth. Here's an example:
main.swift127 chars6 lines
In this example, we multiply the number by 1000 to get the three decimal places, use the round()
function to round it to the nearest integer, and then divide by 1000 to get the decimal number back.
gistlibby LogSnag