Get items appearing on the sheet, still a lot to do but this is a strong step in the right direction
This commit is contained in:
parent
6b03d62234
commit
23a402f11a
9 changed files with 254 additions and 10 deletions
20
module/utils/roundToPrecision.mjs
Normal file
20
module/utils/roundToPrecision.mjs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* Takes a possibly-decimal value and rounds after a certain precision, keeping
|
||||
* only the specified amount of decimals.
|
||||
*
|
||||
* @param {number} value The value that is to be rounded.
|
||||
* @param {number} precision The number of decimal places to round to. Must be a
|
||||
* positive integer.
|
||||
* @returns The rounded number
|
||||
*/
|
||||
export function toPrecision(value, precision = 1) {
|
||||
if (!Number.isInteger(precision)) {
|
||||
throw `Precision must be an integer`;
|
||||
};
|
||||
if (precision < 0) {
|
||||
throw `Precision must be greater than or equal to 0`;
|
||||
};
|
||||
|
||||
const m = 10 ** precision;
|
||||
return Math.round(value * m) / m;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue