Fri Sep 17, 2021 10:30 am
Login Register Lost Password? Contact Us


issue with roundup

Topics specific to the use of the ECL IDE

Thu Mar 18, 2021 2:51 pm Change Time Zone

I had a strange issue with Roundup function. The roundup is broken for numbers less than 0.1 (roundup to 0 instead of 1) when I calculate a decimal number and round it up to assign to a second attribute. However when I did a 2nd project using the same roundup statement and assign to a third attribute, it worked! I really want to understand the issues here since this problem is really hard to detect! It's causing unwanted result without us knowing for a while. Appreciate any input!

My WUID# W20210318-101352 (alpha dev).

Best regards,
Michelle
gogreen
 
Posts: 1
Joined: Fri May 18, 2012 12:45 pm

Mon Mar 22, 2021 11:51 am Change Time Zone

Michelle,

Please post your code that demonstrates this problem.

Remember, this is a globally public forum, so internal LNRS workunit IDs are unavailable to anyone outside LNRS (and many inside that do not have access to your work environment).

Also, the ROUNDUP() docs say:
The ROUNDUP function returns the rounded integer of the realvalue by rounding any decimal portion to the next larger integer value, regardless of sign.

So that "regardless of sign" means that this code is all correct:
Code: Select all
DECIMAL5_2 Pos := 2.2;
DECIMAL5_2 Neg := -2.2;
ROUNDUP(Pos);  //3
ROUNDUP(Neg);  //-3


HTH,

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1593
Joined: Wed Oct 26, 2011 7:40 pm

Mon Mar 22, 2021 5:43 pm Change Time Zone

Michelle,

To expand on my previous reply, if what you need is a true "round up" that works on both positive and negative numbers, then here's my solution:
Code: Select all
DECIMAL5_2 Pos := 2.2;
DECIMAL5_2 Neg := -2.2;
ROUNDUP(Pos);  //3
ROUNDUP(Neg);  //-3

MyRoundUp(REAL8 r) := IF(r < 0,TRUNCATE(r),ROUNDUP(r));
MyRoundUp(Pos); //3
MyRoundUp(Neg); //-2

HTH,

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1593
Joined: Wed Oct 26, 2011 7:40 pm


Return to ECL IDE

Who is online

Users browsing this forum: No registered users and 1 guest

cron