# "round with 2 decimal digits"

...the round() gives back a 0 decimal digit number.. what about if I want 2 decimal digits?

like: round(5.045, 2); -> 5.05

ex:
97,615 + 97,615 = 195,23

<>

97,62 + 97,62 = 195,24
Hello,

The round function available by default at outsystems, round the decimal value to nearest integer.
To round with decimal places you need to create an .net extension.
Use the extension as attachment, that i create with that functionality and others.

Nelson Inácio

Can't open the file....
You don't necessarily need to create an extension to round to 2 decimal digits. Follow my thoughts:

98.7654321 * 100 = 9876.54321
round (9876.54321) = 9876
9876 / 100 = 98.76

So a round (number, n) where n is the number of digits and number is the number to round, could be obtained by:

round (number * power (10, n)) / power (10, n).

So you can create a simple Service Studio action or function that does this with a simple assign on the inputted value.
I develop this extension on outsystems 4.1, probably you are using the 4.0 version.
Although that's a good workaround, it feels clumbsy as a regular method...
We often require a round(x, n digits) function on several projects, so we just keep copying/recreating it... maybe this can be promoted as a built-in action in the future?...
Hi Paulo

The problem (I think) with built-in actions is that, everytime one needs to create a new one, it must be done by the manufacturer (in this case OutSystems) - it becomes a centralized effort and loses agility.

I myself am more of a library adept. What I think should exist (if it does not already) is a true Math library (most likely in the form of an extension). Both Java and C# already possess the necessary functionality in their underlying libraries, so it would be just a matter of mapping them to OutSystems functions.
Hi Acácio,

I agree with you, although I would consider this feature one of those that may have been on the 'basic' built-in set...
A strong built-in set of features is specially important to new users of the platform, who may not yet have the mindset of searching the community for new extensions.