Last active
January 26, 2017 21:00
-
-
Save mido3ds/b456bcb1c5be1009963fa986cf4a42b3 to your computer and use it in GitHub Desktop.
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
#include <cmath> | |
#include <cassert> | |
// round num to given precision | |
double Round(const double &num, const int precision) | |
{ | |
int helper = pow(10, precision); | |
// check helper is not zero | |
assert(helper != 0 && "dividing on zero"); | |
return (roundf(num * helper) / helper); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment