round<T extends num> static method
Rounds n
to a precision of precision
. The returned value is of the
same type as n
.
Implementation
static T round<T extends num>(num n, [ int precision = 0 ]) {
if (precision == 0) {
if (T == double || T == num) {
return n.roundToDouble() as T;
}
else if (T == int) {
return n.round() as T;
}
else {
throw "can't round to type [${T}]";
}
}
num factor = Math.pow(10, precision);
return EZ.round<T>(n * factor) / factor as T;
}