Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Average function?

  • 04-09-2006 9:50am
    #1
    Registered Users, Registered Users 2 Posts: 224 ✭✭


    Hi
    I m currently creating an ASP page which Im using VB Script with. I need to come up with a way to calculate an average of an ever changing amount of fields. The total sum is made up of a max of 3 different figures depending on the item you choose.
    e.g. item1 is made up of a unitcost, printcost and freightcharge. Each cost is margined. so to say for arguements sake each cost had a % margin of 20%, then you would add 20+20+20 & divide by 3.
    Now Item2 might only have unitcost and freight charge, so Id be adding up only 2 margins and dividing by 2. and so on...

    Is there a way I can determine the amount of fields and average the margins depending on the amount of fields in the equation

    Any ideas


Comments

  • Registered Users, Registered Users 2 Posts: 4,188 ✭✭✭pH


    Just count the number of items and divide at the end:
    total = 0
    count = 0;
    avg = 0;
    for each item {
     total = total + margin
     count++
    }
    if (count > 0) {
     avg = total / count
    }
    

    However, adding the margin percentages together and dividing at the end will not give you a meaningful figure - average or otherwise. To calculate an average margin you need to add the actual amounts (in cents) together and divide by the total amount. Adding percentages together will give a meaningless result.


Advertisement