Wed May 12, 2021 5:45 am

issue with roundup

Topics specific to the use of the ECL IDE
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

Michelle,

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);  //3ROUNDUP(Neg);  //-3`

HTH,

Richard
rtaylor

Posts: 1581
Joined: Wed Oct 26, 2011 7:40 pm

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);  //3ROUNDUP(Neg);  //-3MyRoundUp(REAL8 r) := IF(r < 0,TRUNCATE(r),ROUNDUP(r)); MyRoundUp(Pos); //3MyRoundUp(Neg); //-2`

HTH,

Richard
rtaylor