01-27-2011 10:44 AM
Hi,
Please, could somebody help me??
I would like to solve this aritmethic expression but without rounding. I found some commands like TRUNC, FRAC etc; but it doesn't help me. I didn't find any article in internet explanning it.
The result must be 4.14 instead of 4.40!
DATA: vl_total_frete(15) TYPE n ,
vl_icsf(15) TYPE p DECIMALS 2,
vl_aliq_cof(6) TYPE n .
WRITE '54.55' TO vl_total_frete.
WRITE '7.60' TO vl_aliq_cof .
*vl_icsf = ( ( vl_total_frete * vl_aliq_cof ) / 100 ).*
Thanks,
Marcos F. Dotta
Edited by: Marcos Dotta on Jan 27, 2011 11:44 AM
01-27-2011 11:01 AM
HI
Check the below code
DATA: vl_total_frete(15) TYPE p decimals 2,
vl_icsf(15) TYPE p DECIMALS 3, " Change the decimals to 2 and check again
vl_aliq_cof(6) TYPE p decimals 2.
vl_total_frete = '54.55'.
vl_aliq_cof = '7.60'.
* Since type n accepts numbers after decimals but while calculating they are not taken into account
* It is merely acting as string/Char type while accepting the value but not at the time of Calculation
vl_icsf = ( ( vl_total_frete * vl_aliq_cof ) / 100 ).
Cheerz
Ram
01-27-2011 11:00 AM
HI,
Hope this helps
DAtA : w_data1 like vl_total_frete,
w_data2 like vl_aliq_cof.
WRITE '54.55' TO vl_total_frete.
WRITE '7.60' TO vl_aliq_cof .
w_data1 = ABS(vl_total_frete).
w_data2 = ABS(vl_aliq_cof).
vl_icsf = ( ( w_data1 * w_data2 ) / 100 ).
Basically this w_data1 wil be equal to 55 & w_data2 = 8
*vl_icsf wil be equal to 4.40
Regards,
Akhila Bidare
01-27-2011 11:10 AM
Hi Akhila,
But the result can not be 4.40 but 4.14... You code didn't work, sorry!!
The rounding must not happen!
Thanks,
Marcos F. Dotta
01-27-2011 11:01 AM
HI
Check the below code
DATA: vl_total_frete(15) TYPE p decimals 2,
vl_icsf(15) TYPE p DECIMALS 3, " Change the decimals to 2 and check again
vl_aliq_cof(6) TYPE p decimals 2.
vl_total_frete = '54.55'.
vl_aliq_cof = '7.60'.
* Since type n accepts numbers after decimals but while calculating they are not taken into account
* It is merely acting as string/Char type while accepting the value but not at the time of Calculation
vl_icsf = ( ( vl_total_frete * vl_aliq_cof ) / 100 ).
Cheerz
Ram
01-27-2011 12:56 PM
Hi Marcos,
Firstly, you have to use type p and not type n when you deal with decimals.
Secondly, WRITE statement copies the number like a character and not a number.
If you want to do type-casting then you have to use MOVE.
E.G.
DATA: vl_total_frete(15) TYPE p DECIMALS 2 ,"Type p not n
vl_icsf(15) TYPE p DECIMALS 2,
vl_aliq_cof(6) TYPE p DECIMALS 2 ."Type p not n
MOVE '54.55' TO vl_total_frete. "Use Move instead of write
MOVE '7.60' TO vl_aliq_cof . "Use Move instead of write
vl_icsf = ( ( vl_total_frete * vl_aliq_cof ) / 100 ).
WRITE vl_icsf.
Regards,
Jovito
01-27-2011 2:19 PM
Jovito's solution works correctly, however keep in mind that your calculations result is actually 4.1458, so what gets stored into vl_icsf will be 4.15, not 4.14. in essence it IS still being rounded, but you are now able to retain 2 decimal places.