‎2007 May 16 8:03 AM
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.
‎2007 May 16 8:12 AM
What you can also do is split the amount on '.', get the second part in lenght 2 and concatenate again them.
Peter
‎2007 May 16 8:15 AM
hello,
Assign the value to a variable defined as Type p decimal 1
and move the value to variable Type p decimal 2.
‎2007 May 16 9:13 AM
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
‎2007 Jun 19 5:40 AM
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!!
‎2007 Jun 19 5:42 AM
Hi,
Try to use the ROUND function module by passing '-' in sign parameter
Thanks
Naren
‎2007 Jun 19 5:45 AM
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
‎2007 Jun 19 5:46 AM
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