Is there a way to modify the Round() function in Built-in Functions ?
Application Type
Traditional Web

Currently my code is using Round() function in Built-in Functions in many places.

But I want to modify the Round() function to:

- Round(2.5) = 2 => Round(2.5) = 3

- At least code changes.

So I thought about how to modify or override Round() function in Built-in Functions.

Is there a way to modify or override the Round() function in Built-in Functions ? or similar solution to edit Round() function

Thanks


Hi Mai Loc,

There's no way to override a built-in function. Easiest thing to do is to implement your own Round-function that rounds away from zero. I think there's also one in MathUtils in the Forge.

Although you cannot override a built-in function, you can quite easily replace all existing occurrences with the new function.

Goodluck!
Lennart 

Thanks for your answer. Wish you a good day. :D

Thank you for your support. Wish you a good day :D

Please take into account that when you use Round() in a query, it already uses the Database-round, which is already Away from Zero by default, so you don't need to replace those. The documentation says the following about this:

The round method applied depends on where the function is used:
- In expressions in client-side and server-side logic, applies the method round half to even (rounds to the nearest integer, 0.5 rounds to the nearest even integer).
- In aggregates that query SQL Server or Oracle databases, applies the method round half away from 0 (rounds to the nearest integer, 0.5 rounds the number further away from 0).
- In aggregates that query iDB2 databases, applies the method round half up (rounds to the nearest integer, 0.5 rounds up).

Thank you for the reminder. I already know this.

mvp_badge
MVP

Several forge components exist with different round functions. No need to re invent the wheel again

Hi Daniël Kuhlmann,

Thank you for answering my question. I want to ask a few things.

I don't want to edit the code where the Round() function is being used, but just want to change the code inside the Built-in Functions Round() function.

I have to because in my code there are more than 500 places using Round() function and I don't want to change the code in those 500 places.

Do you have a way to do this?

Thanks.

mvp_badge
MVP

As said before, you cannot change build in functions. Instead you need to follow the following approach in future development.

1. Develop the round function as you need (or use one you find on the Forge that fits your purpose

2. Use Search and Replace to replace all the build in instances with your version.,

Next time before you use a build in function in 500 places, first ensure it is what you need. To avoid you need to change something in 500 places you could have created your own round function (and use the buildin round function inside it with some extra logic, or completely your own logic).

Thanks for your answer. Wish you a good day. :D

mvp_badge
MVP

Search on Round()

Then use the Replace all occurences button in the search result panel.

@Mai Loc

Just press Ctrl+R and replace from all over the place in the module

Have you solved your issue? If yes then mark as solved this question. It would help others solve when facing with same issues.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.