MCPcopy Create free account
hub / github.com/Script-Hub-Org/Script-Hub / createRound

Function createRound

script-converter.js:671–686  ·  view source on GitHub ↗
(methodName)

Source from the content-addressed store, hash-verified

669}
670
671function createRound(methodName) {
672 const func = Math[methodName]
673 return (number, precision) => {
674 precision = precision == null ? 0 : precision >= 0 ? Math.min(precision, 292) : Math.max(precision, -292)
675 if (precision) {
676 // Shift with exponential notation to avoid floating-point issues.
677 // See [MDN](https://mdn.io/round#Examples) for more details.
678 let pair = `${number}e`.split('e')
679 const value = func(`${pair[0]}e${+pair[1] + precision}`)
680
681 pair = `${value}e`.split('e')
682 return +`${pair[0]}e${+pair[1] - precision}`
683 }
684 return func(number)
685 }
686}
687function round(...args) {
688 return createRound('round')(...args)
689}

Callers 1

roundFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected