Application Development and Automation 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: 
Read only

Decimal_Number_Query??

Former Member
0 Likes
852

Hi..

I am doing some calculations in my code to get a value in a variable,Now, I

want to check whether that variable is having a decimal or not.

If it is having a decimal ie. it is a number like 1.7485, then I need to

initialize this variable.

Please tell me how shall I proceed?

Thanks

6 REPLIES 6
Read only

Former Member
0 Likes
807

Use FRAC which will give you the decimal part of the input parameter.

Then you can decide to initialize it.

Regards,

Ravi

Read only

0 Likes
807

either use FRAC or pass it some string and use

if str CP '.' .

str = 0.

endif.

reward points if it helps

regds

gunjan

Read only

Former Member
0 Likes
807

Hi,

I assume that the variable 1.7845 is an internal table field. Now declare two more variable in your internal table say itab-var & itab-decimal.

Now loop the internal table and split the variable at the decimal point.

loop at itab.

split itab-var at '.' into var decimal.

modify itab transporting var decimal

endloop.

Now var field will contain values before decimal points and decimal field will contain values after decimal points.

With this you can once again loop the internal table and initialize the varaiable.

loop at itab.

if itab-decimal ne space.

clear itab-fieldname.

modify itab transporting fieldname.

endif.

endloop.

Lakshminarayanan

P.S. Mark all helpful answers for points

Read only

Former Member
0 Likes
807

check out the FM: SWA_DETERMINE_DECIMALS

If there are no decimal places, the return value will be zero.

Plz reward points if this helps!!

Thanx,

Rajeev

Read only

Former Member
0 Likes
807

Hi Subhash,

You can do this using <b>FRAC</b> which returns Decimal part of the given number as follows:

For Ex:

DATA: M TYPE F VALUE '-3.5',

D TYPE P DECIMALS 1.

D = FRAC( M ).

Result:D = '-0.5'

and can initialize this variable.

<b>Kindly reward if helpful.</b>

Regards,

Shakuntala

Read only

Former Member
0 Likes
807

Hi Subhash,

You can do this using <b>FRAC</b> which returns Decimal part of the given number as follows:

For Ex:

DATA: M TYPE F VALUE '-3.5',

D TYPE P DECIMALS 1.

D = FRAC( M ).

Result:D = '-0.5'

and can initialize this variable.

<b>Kindly reward if helpful.</b>

Regards,

Shakuntala