Reputation: 203
I am writing a report for an MRP program and it contains a field I calculate for the quantity to order. I need to round the number up if it is a decimal point.
For example: 2.33 needs to be rounded up to 3 and so on.
I have tried
oder = round(order,0).
but that just get me 2.00 I need that number to be rounded up to the next whole number.
Upvotes: 3
Views: 9991
Reputation: 123
This will work for negative values too. Return value is intentionally kept as Integer, you can keep it as Decimal too.
function roundUp returns integer
(
input in-value as DECIMAL
):
def var x as decimal no-undo.
def var y as decimal no-undo.
if in-value < 0 then
DO:
x = truncate(in-value,0).
y = in-value - x.
if abs(y) <= 0.5 then
return INTEGER(x).
else
return INTEGER(round(in-value,0)).
END.
ELSE
return INTEGER(round(in-value,0)).
end function.
Upvotes: 0
Reputation: 1
Use the following:
DEF VAR X AS decimal.
DEF VAR Y AS integer.
update
x with frame a.
Y = X - 1.
display y.
IF (( X - Y ) < 0.5)
THEN do:
DISPLAY round(x,0) + 1.
end.
ELSE DO :
DISPLAY round(x,0).
end.
Upvotes: -1
Reputation: 29
x = round(n + 0.4999999999, 0)
... should work for all for negative values of n too
roundUp() resolves to -1 in all the above negative values of n
Upvotes: 2
Reputation: 14020
function roundUp returns integer ( x as decimal ):
if x = truncate( x, 0 ) then
return integer( x ).
else
return integer( truncate( x, 0 ) + 1 ).
end.
display roundUp( 2.33 ).
Upvotes: 6