Skip to content

Instantly share code, notes, and snippets.

@mido3ds

mido3ds/roundNumber.h

Last active Jan 26, 2017
Embed
What would you like to do?
#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
You can’t perform that action at this time.