Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Rounding down values

Former Member
0 Kudos

Hi experts,

Need to round down values for ex.

22321.428571. Therefore, we would want this figure displayed as: 22321.42 not 22321.43.

How can I do this? Thanks.

7 REPLIES 7

Peter_Inotai
Active Contributor
0 Kudos

What you can also do is split the amount on '.', get the second part in lenght 2 and concatenate again them.

Peter

Former Member
0 Kudos

hello,

Assign the value to a variable defined as Type p decimal 1

and move the value to variable Type p decimal 2.

0 Kudos

check this code

DATA: dec2 TYPE p DECIMALS 2 VALUE '22.23',

dec1 TYPE p DECIMALS 1,

ld_str(50) TYPE c.

ld_str = dec2.

SHIFT ld_str RIGHT DELETING TRAILING ' '.

SHIFT ld_str RIGHT BY 1 PLACES.

SHIFT ld_str LEFT DELETING LEADING ' '.

dec1 = ld_str. "result will be 22.2

-


reward points if answered

Former Member
0 Kudos

TRUNC(a,n) is an arithmetic function with the following result (for the values a and n):

TRUNC(a) – truncate the decimal places of a

TRUNC(a,n) – truncate the number a after n decimal places

TRUNC(a,-n) – set n places in the number a before the decimal point to 0

Have a Good day!!

Former Member
0 Kudos

Hi,

Try to use the ROUND function module by passing '-' in sign parameter

Thanks

Naren

Former Member
0 Kudos

here is the sample code with function modele for 1 decimal ...just increase decimal places in the function modules input ...so that your decinal values will be as you want ....

DATA: dec2 TYPE p DECIMALS 2 VALUE '22.234',
      dec1 TYPE p DECIMALS 1,
      ld_str(50) TYPE c.


CALL FUNCTION 'ROUND'
  EXPORTING
    decimals      = 1
    input         = dec2
    sign          = '-'  "Negative Rounding Concept
  IMPORTING
    output        = dec1 "result will be 22.2
  EXCEPTIONS
    input_invalid = 1
    overflow      = 2
    type_invalid  = 3
    OTHERS        = 4.

reward points if it is usefull ....

Girish

Former Member
0 Kudos

Hi .... here is the code for Rouding down without Rounding to nearest value...

*Rounds a value DOWN to 1 decimal using char manipulation
DATA: dec2 TYPE p DECIMALS 2 VALUE '22.25',
      dec1 TYPE p DECIMALS 1,
      ld_str(50) TYPE c.

ld_str = dec2.
SHIFT ld_str RIGHT DELETING TRAILING ' '.
SHIFT ld_str RIGHT BY 1 PLACES.
SHIFT ld_str LEFT DELETING LEADING ' '.
dec1 = ld_str.  "result will be 22.2

Reward points if it is usefull ...

Girish