Round formula for calc element

Status
Not open for further replies.

marioms

Member
Hello peeps,

I have a question. I want to make a calc element with a formula for rounding up a number from a field in the form. I want it following 3 simple rules and ill show them in the examples:

- Number from 0 to 24 rounds to 0.

- Number from 25 to 74 rounds to 50.

- Number from 75 to 100 rounds to 100.

Examples:

- If I input 365 the calc element field will show 350
- If I input 489 the calc element field will show 500
- If I input 126 the calc element field will show 150
- If I input 770 the calc element field will show 800
- If I input 115 the calc element field will show 100

I tried to code but I am a mess... It would be a huge help, thanks!!!
 
I think your 4th example does not follow your rules. A 770 input should round down to 750 correct?

Try this:
PHP:
$num = (int) '{tablename___elementname}';
return round($num * 2 / 100, 0) * 100 / 2;

You will need to replace tablename___elementname with your actual input element's name.
 
It works like a charm and you are right, the 4th example was wrong, it should be 750 instead 800, thanks a lot!!!
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top