Hey All...
Plz check the following piece of code.
parameters: sec type i.
data: min type i,
bals type i.
min = sec / 60.
bals = sec mod 60.
if bals > 30.
min = min + 1.
endif.
write:/ 'Second(s)', sec, '=', min, 'Minute(s)'.
Give the input as 515 and chk out the result.
We expect the result to be 9.
But system shows answer as 10.
Plz chk.!
Hi,
This is normal, as MIN is equal to '9' because it's rounded, in reality it should be '8.46'.
You must use something like this :
min = TRUNC( sec / 60 ).
<b>This is the right piece of code :</b>
parameters: sec type i. data: min type i, bals type i, x type p decimals 3. x = sec / 60. min = trunc( x ) . bals = sec mod 60. if bals > 30. min = min + 1. endif. write:/ 'Second(s)', sec, '=', min, 'Minute(s)'.
Hope this helps,
Erwan
Add a comment