f
This commit is contained in:
@@ -7,6 +7,16 @@ export function safeTruncate(num, decimals = 2) {
|
||||
return (scaled / factor).toFixed(decimals)
|
||||
}
|
||||
|
||||
function toTruncatedCents(num) {
|
||||
if (Number.isNaN(num) || !Number.isFinite(num))
|
||||
return 0
|
||||
return Math.trunc((num + Number.EPSILON) * 100)
|
||||
}
|
||||
|
||||
function centsToFixed(cents) {
|
||||
return (cents / 100).toFixed(2)
|
||||
}
|
||||
|
||||
function calculatePlatformOverpricingCost(price, config) {
|
||||
if (price <= config.p_pricing_standard)
|
||||
return 0
|
||||
@@ -37,10 +47,12 @@ export function calculatePromotionPricing(priceInput, config) {
|
||||
const platformOverpricingCost = calculatePlatformOverpricingCost(price, config)
|
||||
const superiorOverpricingCost = calculateSuperiorOverpricingCost(price, config)
|
||||
const totalCost = baseCost + platformOverpricingCost + superiorOverpricingCost
|
||||
const revenue = price - totalCost
|
||||
const priceCents = toTruncatedCents(price)
|
||||
const costCents = toTruncatedCents(totalCost)
|
||||
const revenueCents = priceCents - costCents
|
||||
|
||||
return {
|
||||
costPrice: safeTruncate(totalCost),
|
||||
promotionRevenue: safeTruncate(revenue),
|
||||
costPrice: centsToFixed(costCents),
|
||||
promotionRevenue: centsToFixed(revenueCents),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user