1
0
Fork 0
mirror of https://github.com/sbrl/terrain50-cli.git synced 2024-06-29 10:54:56 +00:00
terrain50-cli/src/Helpers/MathsHelpers.mjs

16 lines
530 B
JavaScript

"use strict";
/**
* Convenience function for calculating the percentage betwween 2 given values.
* @param {Number} count_so_far The fractional part (e.g. items done so far)
* @param {Number} total The total part (e.g. the total number of items to do)
* @param {Number} [range=100] The range to transform to (default: 100)
* @return {Number} The calculated percentage.
*/
function percentage(count_so_far, total, range=100) {
if(count_so_far == 0) return 0;
return (count_so_far/total)*range;
}
export { percentage };