[refactor] Moved 'roundToTwo' to its own TS file

This commit is contained in:
Steven Evans 2018-07-04 20:22:29 -04:00
parent e16ca2abb5
commit 39c9488768
4 changed files with 13 additions and 10 deletions

@ -16,8 +16,8 @@ import {Settings} from "./Settings";
import {parse} from "../utils/acorn"; import {parse} from "../utils/acorn";
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {compareArrays, printArray, import {compareArrays, printArray} from "../utils/HelperFunctions";
roundToTwo} from "../utils/HelperFunctions"; import {roundToTwo} from "../utils/helpers/roundToTwo";
import {isString} from "../utils/StringHelperFunctions"; import {isString} from "../utils/StringHelperFunctions";
function WorkerScript(runningScriptObj) { function WorkerScript(runningScriptObj) {

@ -36,9 +36,9 @@ import {parse, Node} from "../utils/acorn";
import {dialogBoxCreate} from "../utils/DialogBox"; import {dialogBoxCreate} from "../utils/DialogBox";
import {Reviver, Generic_toJSON, import {Reviver, Generic_toJSON,
Generic_fromJSON} from "../utils/JSONReviver"; Generic_fromJSON} from "../utils/JSONReviver";
import {compareArrays, createElement, import {compareArrays, createElement} from "../utils/HelperFunctions";
roundToTwo} from "../utils/HelperFunctions";
import {formatNumber} from "../utils/StringHelperFunctions"; import {formatNumber} from "../utils/StringHelperFunctions";
import {roundToTwo} from "../utils/helpers/roundToTwo";
var keybindings = { var keybindings = {
ace: null, ace: null,

@ -242,11 +242,6 @@ function powerOfTwo(n) {
return n && (n & (n-1)) === 0; 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, export {sizeOfObject,
clearObject, clearObject,
addOffset, addOffset,
@ -255,7 +250,6 @@ export {sizeOfObject,
compareArrays, compareArrays,
printArray, printArray,
powerOfTwo, powerOfTwo,
roundToTwo,
clearEventListenersEl, clearEventListenersEl,
removeElementById, removeElementById,
removeElement, removeElement,

@ -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`);
}