lion/packages/localize/src/number/roundNumber.js
Joren Broekema 09d9675963 feat(localize): add types to localize
Co-authored-by: narzac <narzac@gmail.com>
2020-08-03 17:00:26 +02:00

20 lines
502 B
JavaScript

/**
* Round the number based on the options
*
* @param {number} number
* @param {string} roundMode
* @throws {Error} roundMode can only be round|floor|ceiling
* @returns {number}
*/
export function roundNumber(number, roundMode) {
switch (roundMode) {
case 'floor':
return Math.floor(number);
case 'ceiling':
return Math.ceil(number);
case 'round':
return Math.round(number);
default:
throw new Error('roundMode can only be round|floor|ceiling');
}
}