tickle/modules/utils/percentFromProgress.mjs

11 lines
351 B
JavaScript
Raw Permalink Normal View History

2023-06-06 22:45:16 +00:00
//@ts-check
/**
* Returns a formatted percent from a given fraction.
* @param {number} fraction any fractional number, e.g, 5/10
2023-06-13 16:50:13 +00:00
* @param {boolean} [pad]
2023-06-06 22:45:16 +00:00
*/
2023-06-13 16:50:13 +00:00
export const percentFromProgress = (fraction, pad = false) =>
/** @type {`${string}%`} */ (Math.round(fraction * 100) + "%").padStart(pad? 3 : 0, "0");
2023-06-06 22:45:16 +00:00
export default percentFromProgress