Skip to Content
Author's profile photo Former Member

Simple routine to convert exponential values to float

Dear all,

I was trying to get values in an ALV grid recently and I noticed that the values are displayed as exponential values which didn’t satisfy the client very much. So after a little research I found this function module that converted the exponential format to float format.

This form takes the exponential value in V_FLOAT variable converts it to the float value in V_CHAR P10_4 variable

FORM CONVERT CHANGING V_FLOAT V_CHAR P10_4.

   IF V_FLOAT IS NOT INITIAL.

   CALL FUNCTION ‘CEVA_CONVERT_FLOAT_TO_CHAR’

   EXPORTING

     FLOAT_IMP  = V_FLOAT

     FORMAT_IMP = P10_4

     ROUND_IMP  = ‘ ‘

  IMPORTING

    CHAR_EXP = V_CHAR.

  ENDIF.

ENDFORM.

DATA: V_FLOAT TYPE F , V_CHAR(25), P10_41(10) TYPE P DECIMALS 3.     “CONVERSION OF STRING TO FLOAT STRUCTURE.

V_FLOAT = VALUE_BEFORE_CONVERSION.

PERFORM CONVERT CHANGING V_FLOAT V_CHAR P10_41.

VALUE_AFTER_CONVERSION  = V_CHAR.

Hope this simple routine is useful.

If you have any doubts, please don’t hesitate to ask.

Regards,

Mohammed Mohsen

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Martin Coetzee
      Martin Coetzee

      On another thread I saw this which worked for me:

      https://archive.sap.com/discussions/thread/3603763

      By a previous member called Armin:

      Hi,

      the SET_EDIT_MASK method was very helpfull.

      It took me some time to find out that lr_column->set_edit_mask( '==DEC2' ) means use function CONVERSATION_EXIT_DEC2_OUTPUT for converting the numbers.

      Best regards

      Armin

       

      I found this really useful. I implemented it easily and it worked.

      Before I applied the code:

      I put in this code:

      * Set the column optimisation, texts, visibility etc
        gr_columns = lt_alv_table->get_columns( ) .
      * Optimize column width
        gr_columns->set_optimize( abap_true ).
      * Redo column headings
        gr_column ?= gr_columns->get_column( 'MTBF' ).
        gr_column->set_edit_mask( '==DEC2' ) .
      

      And I ended with this:

      Worked really well.