fround method
Adjust the precision of value
according to context
.numPrecision.
8 By default.
precision
to force
Implementation
num fround(Contexts context, num value, [int precision]) {
if (value is int) return value;
final _precision = (precision == null || precision == -1)
? context?.numPrecision
: precision;
// add "epsilon" to ensure numbers like 1.000000005 (represented as 1.000000004999....) are properly rounded...
final double result = value + 2e-16;
return (_precision == null)
? value
: double.parse(result.toStringAsFixed(_precision));
//2.3.1
// Node.prototype.fround = function(context, value) {
// var precision = context && context.numPrecision;
// //add "epsilon" to ensure numbers like 1.000000005 (represented as 1.000000004999....) are properly rounded...
// return (precision == null) ? value : Number((value + 2e-16).toFixed(precision));
// };
}