bitburner-src/utils/helpers/roundToTwo.ts

10 lines
262 B
TypeScript
Raw Normal View History

/**
* Rounds a number to two decimal places.
* @param decimal A decimal value to trim to two places.
*/
2021-05-01 09:17:31 +02:00
export function roundToTwo(decimal: number): number {
2021-09-05 01:09:30 +02:00
const leftShift: number = Math.round(parseFloat(`${decimal}e+2`));
2018-07-18 18:49:46 +02:00
2021-09-05 01:09:30 +02:00
return +`${leftShift}e-2`;
}