@genexus/web-standard-functions
Version:
GeneXus JavaScript standard functions library for web generators
23 lines • 735 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.roundToEven = void 0;
/**
* Rounds to even the given number to the specified number of decimal digits
* @param {number} value
* @param {number} digits
* @returns number
*/
const roundToEven = (value, digits) => {
let result;
const multiplier = Math.pow(10, digits || 0);
const valToRound = value * multiplier;
const decimalPart = valToRound - Math.trunc(valToRound);
let rounded = Math.round(valToRound);
if (decimalPart === 0.5 && rounded % 2 !== 0) {
rounded = rounded - 1;
}
result = rounded / multiplier;
return result;
};
exports.roundToEven = roundToEven;
//# sourceMappingURL=roundToEven.js.map