roundToPrecision method
Rounds the validated number to a specified number of decimal precision.
For example, (10.12345).roundToPrecision(2) will return 10.12
Implementation
double roundToPrecision(int precision) {
final num value = validate();
if (value is int) return value.toDouble();
if (value is double) {
final num mod = pow(10.0, precision);
return ((value * mod).round().toDouble() / mod);
}
return value.toDouble(); // Should not happen given validate()
}