‎2009 Mar 09 9:34 AM
Hi,
I have a float field which when displayed via write statement shows 3 decimals by default. How can i round it and show 2 decimals. Is there any direct way. I dont want to convert it to string variable & then display.
BYe
‎2009 Mar 09 9:54 AM
data f1 type p decimals 3 value '1575.456'.
write: / f1 decimals 2.
Try the above code snippet to resolve your problem.
Thanks
‎2009 Mar 09 9:36 AM
‎2009 Mar 09 9:36 AM
‎2009 Mar 09 9:40 AM
Hi.
If you are using float type then following piece of code might be useful for you.
Suppose your value is 1.234 and you want it to be rouded of to 1.23
float f = 1.234;
f *= 100;
f = (float)Math.round(f)/100;
.... and now f==1.23
Hope it will help you
thanks
Arun
‎2009 Mar 09 9:43 AM
do like this...
report yztest.
data: test1 type p decimals 3.
test1 = '12.332'.
write:/ test1.
write:/ test1 decimals 2.
‎2009 Mar 09 9:43 AM
Hi mac,
Check this link:
http://help.sap.com/saphelp_nw04/Helpdata/EN/9f/db9e2335c111d1829f0000e829fbfe/frameset.htm
In the write statement just add the decimal option.
WRITE field DECIMALS 2.
Hope this helps.
Regards,
Qamar.
‎2009 Mar 09 9:47 AM
Hi,
For decimals :
write w_field decimals 3.
For exponents:
use exponent option with the field.
while writing,use this.
write 😕 w_float exponent 2.
This is working.
‎2009 Mar 09 9:54 AM
data f1 type p decimals 3 value '1575.456'.
write: / f1 decimals 2.
Try the above code snippet to resolve your problem.
Thanks
‎2009 Mar 09 10:18 AM
Hi Mac,
set the decimals_out = 2. of ur fieldcatalog.
here is a sample program for u to refer.....
REPORT yh1308_sample2.
****TABLE WORK AREA
TABLES:vbak.
***DEFINE INTERNAL TABLE WITH HEADER LINE****
DATA:it_jtab LIKE vbak OCCURS 0 WITH HEADER LINE.
****PROVIDE TYPE GROUP***
TYPE-POOLS:slis.
***MAINTAIN REPORT ID***
DATA:repid LIKE sy-repid,
****DEFINE COLUMN HEADING****
vbak_b TYPE slis_t_fieldcat_alv ,
fs LIKE LINE OF vbak_b.
****START-OF-SELECTION EVENT***
START-OF-SELECTION.
SET PF-STATUS 'STATUS'.
***FUNCTION MODULE COLUMN HEADINGS****
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'VBAK'
CHANGING
ct_fieldcat = vbak_b.
*----------------------------------------------------------------*
*exponent
fs-decimals_out = 5. "decimals in write statement
fs-input = 'X'. " sets field in edit mode
MODIFY vbak_b FROM fs
TRANSPORTING decimals_out input
WHERE fieldname = 'NETWR'.
*---------------------------------------------------------------------
****REPORT ID SYSTEM VARIABLE****
repid = sy-repid.
SELECT * FROM vbak UP TO 20 ROWS INTO TABLE it_jtab.
****FUNCTION MODULE OUTPUT DISPLAY***
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = repid
it_fieldcat = vbak_b
TABLES
t_outtab = it_jtab.
****END OF PROGRAM****
Regards,
Mdi.Deeba
‎2009 Mar 09 10:46 AM
Hi Mac,
If you've got your answer then please mark the thread as ANSWERED.
Thanks.
‎2009 Mar 09 10:51 AM
thanks guys for your valuable time & inputs. You guys are amazing