58.85 displays as 58.84999999999

I am creating a calculator with BSP. When I tested it with different numbers, I ran into the problem that decimal numbers are not displayed correctly.

For instance. 58.85 → 58.849999. But 58.84 or 58.86 work fine. 58.8471 → 54.84710000000001. At the end, the last digit entered will be saved from nowhere.

My following code is below.

method GENERATE_NUM.

  DATA: lv_digi type I.  * number of digits after the decimal point


  call METHOD me->get_decimal
    RECEIVING
      getdigits = lv_digi.

  *if it is a natural number  
  IF lv_digi = 0.
    IF thisnum < 0.
      result = thisnum * 10 - newdigit.
    ELSE.
      result = thisnum * 10 + newdigit.
    ENDIF.

   *if it is a float number
   Else.
    IF thisnum < 0.
      result = thisnum - ( newdigit / 10 ** lv_digi ).
    ELSE.
      result = thisnum + ( newdigit / 10 ** lv_digi ).
    ENDIF.

    *increase the number of decimal point by 1
    call method me->set_decimal.
  ENDif.

endmethod.

What I basically do is every time a number is clicked, it calls the generate_num method. It takes THISNUM, NEWDIGIT, RESULT as parameters.
thisnum = current number (ex: 58.8)
newdigit = number of pressed (ex: 5)
result = generated number (expected: 58.85, but returns 58.849999).

+5
2

, P ( ) float.

:

DATA lv_fixed_point TYPE p LENGTH 16 DECIMALS 2.

. "" . :

- P

P . . . 1 16 . , . 14 . . . P, Fixed . P .

P , , , ..

+7

CALL FUNCTION 'FLOATINGPOINT_COMPARE_ABSOLUTE' IEEE. , :

 IS_EQUAL
 IS_GREATER
 IS_GREATER_EQUAL
 IS_LESS
 IS_LESS_EQUAL

- .

.

. . .

NaN +Inf -Inf ( sNAN, DECFLOAT f).

0

All Articles