Questions and discussion about developing processes and programming in PHP, JavaScript, web services & REST API.
Forum rules: Please search to see if a question has already asked before creating a new topic. Please don't post the same question in multiple forums.
#788418
So I've been working on setting a value to round to the nearest 5 or to the nearest 10 of another value and thought I'd share what I ended up with.

Here's how I did it in a trigger:
Code: Select all
$roundContact = ceil((@#textVar003) / 5) * 5;
@@textVar004=$roundContact;
Here's how I did in in Javascript:
Code: Select all
function roundUp() {
$("#textVar003").setValue(Math.ceil(Number($("#country").getValue()) /5)*5);
}
$("#country").setOnchange(roundUp); // on change
roundUp($('#country').getValue(), ''); // on Load
You can also add numbers before rounding but for me it was tricky so I'll add examples of those too:

Trigger:
Code: Select all
$roundContact = ceil((@#textVar003 + 3) / 5) * 5;
@@textVar004=$roundContact;
Javascript:
Code: Select all
function roundUp() {
$("#textVar003").setValue(Math.ceil((Number($("#country").getValue()) + 2.5)/5)*5);
}
$("#country").setOnchange(roundUp); // on change
roundUp($('#country').getValue(), ''); // on Load
If anyone has a cleaner way of doing this, please feel free to share. I'm a super newbie so I make no guarantees.

If you need it to round to the nearest 10, just change the 5s with 10s.

Hopefully this helps someone in the future trying to do the same.
Want to create your own meme coin?

In the world of cryptocurrencies, a unique and exc[…]

The market for cryptocurrencies is demonstrating a[…]

What's SAP FICO?

Embarking on a dissertation can be one of the most[…]

Hello. For rental housing, there are software solu[…]