MCPcopy Create free account
hub / github.com/avoidwork/filesize.js / applyRounding

Function applyRounding

src/helpers.js:314–334  ·  view source on GitHub ↗
(val, ceil, e, round, roundingFunc, autoExponent)

Source from the content-addressed store, hash-verified

312 * @returns {Object} Object with rounded value and possibly incremented exponent
313 */
314export function applyRounding(val, ceil, e, round, roundingFunc, autoExponent) {
315 let p;
316 if (e > 0 && round > 0) {
317 p = Math.pow(10, round);
318 } else {
319 p = 1;
320 }
321 let r;
322 if (p === 1) {
323 r = roundingFunc(val);
324 } else {
325 r = roundingFunc(val * p) / p;
326 }
327
328 if (r === ceil && e < 8 && autoExponent) {
329 r = 1;
330 e++;
331 }
332
333 return { value: r, e };
334}
335
336/**
337 * Resolves the unit symbol for the given standard, bits mode, and exponent

Callers 2

filesizeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected