问题
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.
回答1:
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 ).
回答2:
x = round(n + 0.4999999999, 0)
... should work for all for negative values of n too
- n = -2.0000001 ... x = -2
- n = -2.5 ... x = -2
- n = -2.9999999999 ... x = -2
roundUp() resolves to -1 in all the above negative values of n
回答3:
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.
来源:https://stackoverflow.com/questions/14584498/how-to-round-up-in-progress-programming