Last active
January 4, 2018 03:08
-
-
Save DJNgoma/7709829da0a4b2643d57 to your computer and use it in GitHub Desktop.
Rounding to the nearest 5 cents in Swift or C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Basic C, but being used in a Swift project of mine. | |
// Just a simple way of getting any floating number to round up or down to a 5 cent figure for calulations. | |
let x = 45.23 | |
let y = 23.58 | |
let z = 82.12 | |
a = round(x/0.05)*0.05 | |
b = round(y/0.05)*0.05 | |
c = round(z/0.05)*0.05 | |
print(a) // 45.25 | |
print(b) // 23.60 | |
print(c) // 82.10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment