StackGenVis: Alignment of Data, Algorithms, and Models for Stacking Ensemble Learning Using Performance Metrics https://doi.org/10.1109/TVCG.2020.3030352
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
StackGenVis/frontend/node_modules/accounting-js/lib/toFixed.js

30 lines
1.0 KiB

4 years ago
import _checkPrecision from './internal/checkPrecision';
import settings from './settings';
/**
* Implementation of toFixed() that treats floats more like decimals
*
* Fixes binary rounding issues (eg. (0.615).toFixed(2) === '0.61') that present
* problems for accounting- and finance-related software.
*
* ```js
* (0.615).toFixed(2); // "0.61" (native toFixed has rounding issues)
* accounting.toFixed(0.615, 2); // "0.62"
* ```
*
* @method toFixed
* @for accounting
* @param {Float} value The float to be treated as a decimal number.
* @param {Number} [precision=2] The number of decimal digits to keep.
* @return {String} The given number transformed into a string with the given precission
*/
function toFixed(value, precision) {
precision = _checkPrecision(precision, settings.precision);
const power = Math.pow(10, precision);
// Multiply up by precision, round accurately, then divide and use native toFixed():
return (Math.round((value + 1e-8) * power) / power).toFixed(precision);
}
export default toFixed;