Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All!

I've got this function that creates formulas:

JavaScript
var calculate = function() {

    var valuePageVisits = (Number.parseFloat(uiStorage.pageVisitsOutput.html().replace(/,/g, '')));
    var valueNewsletterSubscribers = (Number.parseFloat(uiStorage.newsletterSubscribersOutput.html().replace(/,/g, '')));
    var valueSocial = (Number.parseFloat(uiStorage.socialOutput.html().replace(/,/g, '')));
    var valueOpenRate = (Number.parseInt(uiStorage.openRateOutput.html()))/100;
    var valueClickthroughRate = (Number.parseInt(uiStorage.clickthroughRateOutput.html()))/100;
    var valueClickthroughRate2 = (Number.parseInt(uiStorage.clickthroughRateOutput2.html()))/100;
    var valueClickthroughRate3 = (Number.parseInt(uiStorage.clickthroughRateOutput3.html()))/100;
    var valueConversionRate = (Number.parseInt(uiStorage.conversionRateOutput.html()))/100;
    var valueAov = (Number.parseFloat(uiStorage.aovOutput.html().replace(/,/g, '')));
    var valuePartnerCPA = (Number.parseInt(uiStorage.partnerCpaOutput.html()))/100;
    var valueTenancyAmount = (Number.parseFloat(uiStorage.tenancyAmountOutput.html().replace(/,/g, '')));
    var valueScaleCost = (Number.parseInt(uiStorage.scaleCostOutput.html()))/100;

    var forecastedNewsletterConversions = valueNewsletterSubscribers > 0 ? valueNewsletterSubscribers * valueClickthroughRate * valueConversionRate : 0;
    var forecastedPageVisits = valuePageVisits > 0 ? valuePageVisits * valueClickthroughRate2 * valueConversionRate : 0;
    var forecastedSocial = valueSocial > 0 ? valueSocial * valueClickthroughRate3 * valueConversionRate : 0;
    var pageConversions = valuePageVisits > 0 ? valuePageVisits * (valueClickthroughRate + valueClickthroughRate2 + valueClickthroughRate3) * valueConversionRate : 0;
    var forecastedRevenue = ( forecastedPageVisits + forecastedNewsletterConversions + forecastedSocial ) * valueAov;
    var totalActions = (forecastedPageVisits + forecastedNewsletterConversions + forecastedSocial) / valueConversionRate;          var forecastedActionCost = forecastedRevenue * valuePartnerCPA;
    var forecastedScaleCost = forecastedActionCost * valueScaleCost;
    var forecastedTotalCost = forecastedActionCost + forecastedScaleCost + (valueTenancyAmount * valueScaleCost) + valueTenancyAmount;
    var roi = forecastedRevenue != 0 ? (forecastedRevenue/forecastedTotalCost) : 0;


    uiStorage.totalActions.html("£" + Number.parseInt(totalActions).toFixed(2));
    uiStorage.forecastedRevenue.html("£" + Number.parseInt(forecastedRevenue).toFixed(2));
    uiStorage.roi.html("£" + Number.parseFloat(roi).toFixed(2));
    uiStorage.forecastedTotalCost.html("£" + Number.parseInt(forecastedTotalCost).toFixed(2));


All the formulas work perfectly except the one marked in bold, TotalActions. It looks like the division doesn't happen, is the divide symbol incorrect?
If I change the division symbol to a * to multiply, then the formula does work.

Not sure how to make it divide..

Any suggestions?

Thanks very much!!

Mireia

What I have tried:

The issue is in the symbol, when / no division happens, if it's changed to * a multiplication does happen.

Not sure how to make it divide??
Posted
Updated 26-Aug-22 0:29am
Comments
Patrice T 26-Aug-22 6:32am    
What are the 4 values in formula ?
What is actual result ? What result do you expect ?

1 solution

The division operator you used is correct, see, for instance, Division (/) - JavaScript | MDN[^].
Probably you are experiencing another kind of error. Try to post here better details (e.g. the input and the expected output of the expression).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900