Skip to content

Instantly share code, notes, and snippets.

@mido3ds
Last active January 26, 2017 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mido3ds/b456bcb1c5be1009963fa986cf4a42b3 to your computer and use it in GitHub Desktop.
Save mido3ds/b456bcb1c5be1009963fa986cf4a42b3 to your computer and use it in GitHub Desktop.
#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