settings/utils/calculateApiUsage.js

14 lines
308 B
JavaScript
Raw Normal View History

2024-07-30 11:26:42 +00:00
function calculateApiUsage(price, billingUnit, usage, billingBy) {
let _billingUnit = +billingUnit
if (billingBy == 'minute')
_billingUnit = 60 * _billingUnit
const total_cost = (+usage / _billingUnit) * parseFloat(price)
return total_cost.toFixed(10)
}
module.exports = calculateApiUsage