Jump to content

More efficient rounding calculator


Adamhumbug
Go to solution Solved by Barand,

Recommended Posts

Hi All,

I have a rental system - if you rent for 3 or more days over a week you pay for 2 weeks, 3 or more days over 2 weeks and you pay for 3 and so on.

As i need to be able to see how many weeks someone is renting equipment for i have built a js function but wondered if there was a more effience way of getting the weeks value than the following.

            if ($days == 0){
                $weeks = 0
            }else if ($days < 10) {
                $weeks = 1
            } else if ($days >= 10 && $days < 16) {
                $weeks = 2
            } else if ($days >= 17 && $days < 23) {
                $weeks = 3
            } else if ($days >= 24 && $days < 30) {
                $weeks = 4
            }

Thanks as always

Edited by Adamhumbug
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.