Skip to content

Instantly share code, notes, and snippets.

@mbtools
Created November 1, 2022 21:08
Show Gist options
  • Save mbtools/b40dddb96d7316c606118871ef5ee50e to your computer and use it in GitHub Desktop.
Save mbtools/b40dddb96d7316c606118871ef5ee50e to your computer and use it in GitHub Desktop.
Test ABAP round built-in
REPORT ztest_round.
DATA p TYPE p LENGTH 10 DECIMALS 2.
DATA r TYPE p LENGTH 10 DECIMALS 2.
DATA i TYPE i.
DO 6 TIMES.
CASE sy-index.
WHEN 1.
p = '123.49'.
WHEN 2.
p = '123.51'.
WHEN 3.
p = '123.5'.
WHEN 4.
p = '-123.49'.
WHEN 5.
p = '-123.51'.
WHEN 6.
p = '-123.5'.
ENDCASE.
DO 7 TIMES.
i = sy-index - 1.
r = round( val = p dec = 0 mode = i ).
WRITE: / 'In:', p, 'Round:', r, 'Mode:', i.
CASE i.
WHEN 0.
WRITE 'Round to Positive Infinity'.
WHEN 1.
WRITE 'Round away from zero'.
WHEN 2.
WRITE 'Round away from zero if value is exactly half'.
WHEN 3.
WRITE 'Round so last digit is an even no. if value is exactly half'.
WHEN 4.
WRITE 'Round to zero if value is exactly half'.
WHEN 5.
WRITE 'Round to Zero'.
WHEN 6.
WRITE 'Round to Negative Infinity'.
ENDCASE.
ENDDO.
SKIP.
ENDDO.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment