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

Related questions

1 answer 512 views
1 answer 74 views
1 answer 122 views
1 answer 127 views
1 answer 120 views
1 answer 184 views
1 answer 167 views
...