diff --git a/src/NetscriptWorker.js b/src/NetscriptWorker.js index 196e24588..d263a0adb 100644 --- a/src/NetscriptWorker.js +++ b/src/NetscriptWorker.js @@ -16,8 +16,8 @@ import {Settings} from "./Settings"; import {parse} from "../utils/acorn"; import {dialogBoxCreate} from "../utils/DialogBox"; -import {compareArrays, printArray, - roundToTwo} from "../utils/HelperFunctions"; +import {compareArrays, printArray} from "../utils/HelperFunctions"; +import {roundToTwo} from "../utils/helpers/roundToTwo"; import {isString} from "../utils/StringHelperFunctions"; function WorkerScript(runningScriptObj) { diff --git a/src/Script.js b/src/Script.js index 1f76e3b05..2677f2bef 100644 --- a/src/Script.js +++ b/src/Script.js @@ -36,9 +36,9 @@ import {parse, Node} from "../utils/acorn"; import {dialogBoxCreate} from "../utils/DialogBox"; import {Reviver, Generic_toJSON, Generic_fromJSON} from "../utils/JSONReviver"; -import {compareArrays, createElement, - roundToTwo} from "../utils/HelperFunctions"; +import {compareArrays, createElement} from "../utils/HelperFunctions"; import {formatNumber} from "../utils/StringHelperFunctions"; +import {roundToTwo} from "../utils/helpers/roundToTwo"; var keybindings = { ace: null, diff --git a/utils/HelperFunctions.js b/utils/HelperFunctions.js index 8647046b3..3c83f5dee 100644 --- a/utils/HelperFunctions.js +++ b/utils/HelperFunctions.js @@ -242,11 +242,6 @@ function powerOfTwo(n) { return n && (n & (n-1)) === 0; } -//Rounds a number to two decimal places -function roundToTwo(n) { - return +(Math.round(n + "e+2") + "e-2"); -} - export {sizeOfObject, clearObject, addOffset, @@ -255,7 +250,6 @@ export {sizeOfObject, compareArrays, printArray, powerOfTwo, - roundToTwo, clearEventListenersEl, removeElementById, removeElement, diff --git a/utils/helpers/roundToTwo.ts b/utils/helpers/roundToTwo.ts new file mode 100644 index 000000000..b9e3fdbb2 --- /dev/null +++ b/utils/helpers/roundToTwo.ts @@ -0,0 +1,9 @@ +/** + * Rounds a number to two decimal places. + * @param decimal A decimal value to trim to two places. + */ +export function roundToTwo(decimal: number) { + const leftShift: number = Math.round(parseInt(`${decimal}e+2`, 10)); + + return +(`${leftShift}e-2`); +}