How to round a double to the nearest int in Swift

1 Answer

0 votes
import Foundation

var d = 3.2
d = round(d)
print(d)

d = 3.5
d = round(d)
print(d)


print(Int(round(3.2)))
print(Int(round(3.5)))




/*
run:

3.0
4.0
3
4

*/

 



answered Feb 8, 2021 by avibootz
...