12-18-2008 12:33 PM
Hi all!
How do I check if a number has floating point (decimal number)?
Thanks!
12-18-2008 12:35 PM
there are several ways: one would be to take the integer part of the number and check if it is equal to the orignal value.
12-18-2008 12:35 PM
Use CA statement.
Check this:
DATA: num(10) TYPE c VALUE '121212.00'.
IF num CA '.'.
WRITE: 'YES'.
ELSE.
WRITE: 'NO DECIMAL'.
ENDIF.
or you can do like this also.
DATA: num1 TYPE p decimals 2 VALUE '121212'.
DATA num2 TYPE i.
num2 = num1.
IF num2 EQ num1.
WRITE: 'NO DECIMAL'.
ELSE.
WRITE: 'YES'.
ENDIF.
Thanks
12-18-2008 12:35 PM
there are several ways: one would be to take the integer part of the number and check if it is equal to the orignal value.
12-18-2008 12:37 PM
>
> there are several ways: one would be to take the integer part of the number and check if it is equal to the orignal value.
How? Do you have some sample code? Thanks!
12-18-2008 12:47 PM
Hello Ricardo,
Plz try this code:
v_int = trunc( v_num ).
IF v_int = v_num.
WRITE: ' Number has no floating point '
ELSE.
WRITE: ' Number has floating point '
ENDIF.
Hope this is clear.
BR,
Suhas
12-18-2008 12:53 PM
>
> >
> > there are several ways: one would be to take the integer part of the number and check if it is equal to the orignal value.
>
> How? Do you have some sample code? Thanks!
pls. use the code given by Suhas!
12-19-2008 2:18 PM
>
> Hello Ricardo,
>
> Plz try this code:
>
>
> v_int = trunc( v_num ). > > IF v_int = v_num. > WRITE: ' Number has no floating point ' > ELSE. > WRITE: ' Number has floating point ' > ENDIF. >
>
> Hope this is clear.
>
> BR,
> Suhas
Thanks Suhas! I used this and it worked.
12-18-2008 12:50 PM
Hi,
Try this,
data : var(10) TYPE c VALUE '1465.76'.
find '.' in var.
if sy-subrc = 0.
*check sy-subrc and do whatever u want
endif.