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: 

Conversion of char to float causing decimal wrong decimal value

Former Member
0 Kudos

Hi ,

I have float value 2.6000000000000003E-03 which i converted to char using fm  RS_CHECK_CONV_EX_2_IN_NO_DD

the result of it is 0.002600

later when i move the value back to float result is 2.5999999999999993E-03

same code :

data:lv_temp(128),

        lv_value type zflpt. " zfltp domian is FLTP

lv_value = '2.6000000000000003E-03'.

lv_temp = lv_value.

   ls_convert-type = 'P'.

   ls_convert-length = 13.

   ls_convert-decimals = 6.

   ls_convert-ddic_leng = 13.

   ls_convert-sign = c_true.

CALL FUNCTION 'RS_CHECK_CONV_EX_2_IN_NO_DD'

     EXPORTING

       input_external               = lv_temp

       descr                           =   ls_convert

     IMPORTING

       input_i_format               = lv_temp

lv_temp has value 0.002600

but when i move lv_temp to lv_value value is 2.5999999999999993E-03.

Please help me in solving this.

Regards,

Srikanth

3 REPLIES 3

Former Member
0 Kudos

Hi Srikanth,

Can you please specify why you need to convert back from char to float ?

0 Kudos

Hello Rachna agarwal,

Actually we have a scenario we check for the decimals its our application specific, and i ave found solution too by using fm 'CHAR_FLTP_CONVERSION' we ot the desired value, thank you.

thanga_prakash
Active Contributor
0 Kudos

Hello Srikanth,

Try using nthe below FM.

CALL FUNCTION 'CHAR_FLTP_CONVERSION'  "Format conversion: Character --> Floating point

  EXPORTING

*   dyfld = SPACE             "Screen Field name for cursor positioning

*   maskn = SPACE          "Masking character if input screen

*   maxdec = '16'               " t006-decan    Maximum number of input decimal places

*   maxexp = '59+'             " t006-expon    Maximum gross power of 10

*   minexp = '60-'               " t006-expon    Minimum gross power of 10

   string =  <pass ur char value here>                   "CHAR input field for conversion to FLTP

*   msgtyp_decim = 'W'          " sref-msgtyp   Message type for 'TOO_MANY_DECIM' (see domains)

  IMPORTING

    decim =                     "Number of decimal places determined

    expon =                     "Gross power of 10 determined

    flstr =                         "FLTP output field, from CHAR conversion

    ivalu =                        "Value in STRING flag

  EXCEPTIONS

    EXPONENT_TOO_BIG = 1        "               Gross power of 10 is too big

    EXPONENT_TOO_SMALL = 2      "               Gross power of 10 is too small

    STRING_NOT_FLTP = 3         "               STRING cannot be interpreted as floating point

    TOO_MANY_DECIM = 4          "               Too many decimal places.

Regards,

Thanga