Use it like:
import typeCheck from './typeCheck';
/**
* @name round
* @description Write a function that round a number (`n`) to given decimal places.
*
*
* @example Usage:
* round(Math.PI, 2) // => 3.14
*
*
* @param {Number} n The number to be rounded
* @param {Number} places Decimal places
*
* @returns {Number} Rounded number
*/
module.exports.round = function (n, places = 0) {
typeCheck({
param: n,
expected: 'number'
}, {
param: places,
expected: 'number'
})
places = Math.pow(10, places)
return Math.floor(n * places) / places;
}