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

How to move value before decimals to integer

Former Member
0 Likes
5,297

Hi all,

I am having value A which is defined in deciamls.

A = '1.765'.

i want to move the value to B only the digit one.

what B should be defined oF? how many values before the decimal i need to move that many values to b.

generally not more that 2 char A is having before decimal.

A = ' 12.375 ' B = 12

A = 8.65' b = 8.

how can we achieve?

regards

sas

1 ACCEPTED SOLUTION
Read only

Pawan_Kesari
Active Contributor
0 Likes
2,999

>

> Hi all,

>

> I am having value A which is defined in deciamls.

>

> A = '1.765'.

>

> i want to move the value to B only the digit one.

>

> what B should be defined oF? how many values before the decimal i need to move that many values to b.

>

> generally not more that 2 char A is having before decimal.

>

> A = ' 12.375 ' B = 12

>

> A = 8.65' b = 8.

>

> how can we achieve?

>

> regards

> sas

A = FLOOR( A ) .

B = A .

Hi all,

I am having value A which is defined in deciamls.

A = '1.765'.

i want to move the value to B only the digit one.

what B should be defined oF? how many values before the decimal i need to move that many values to b.

generally not more that 2 char A is having before decimal.

A = ' 12.375 ' B = 12

A = 8.65' b = 8.

how can we achieve?

regards

sas

14 REPLIES 14
Read only

Former Member
0 Likes
2,999

field1 type p decimals 0...

field1 = '12.22'

value of field will be 12.....

Read only

Former Member
0 Likes
2,999

I this case, declare b as type i.

b = floor(a).

b will have the value that you wanted.

Hope it helps.

Read only

Pawan_Kesari
Active Contributor
0 Likes
3,000

>

> Hi all,

>

> I am having value A which is defined in deciamls.

>

> A = '1.765'.

>

> i want to move the value to B only the digit one.

>

> what B should be defined oF? how many values before the decimal i need to move that many values to b.

>

> generally not more that 2 char A is having before decimal.

>

> A = ' 12.375 ' B = 12

>

> A = 8.65' b = 8.

>

> how can we achieve?

>

> regards

> sas

A = FLOOR( A ) .

B = A .

Read only

0 Likes
2,999

HI PAWAN

FLOOR is fine or TRUNC keyword is fine?

please any one answer before i relase my transport

Regards

sas

Read only

0 Likes
2,999

I guess in your case FLOOR would do.

Hey. I dont see a keyword called TRUNC. Are you sure about that?

Thanks,

Babu Kilari

Edited by: Babu Kilari on May 6, 2009 7:23 PM

Read only

0 Likes
2,999

>

> I guess in your case FLOOR would do.

>

> Hey. I dont see a keyword called TRUNC. Are you sure about that?

>

> Thanks,

> Babu Kilari

>

> Edited by: Babu Kilari on May 6, 2009 7:23 PM

Hi Babu,

Thanks for your response. If u take F1 help on FLOOR u would observe the TRUNC just down the FLOOR word.Just make a note

My question is for this scenario what best suits FLOOR or TRUNC. sap help is not clear enough to understand is there any one here....

PS: Transport stoped

Regards

sas

Read only

0 Likes
2,999

Hey Sas,

I could see that now. Thanks for the information yaar. If you see that table, Return value description says that trunc function gives you the Value of the integer part of the argument passed. So, this can also be used for your purpose.

But, when you consider the floor function it does the same functionality but generally it is used in a scenario where you are trying to round off the value to the closest integer. Ciel function works in a different way as it round offs the value to the highest integer. So, these two functions depend on the decimal part of the argument that you pass.

So, In your case Floor/Trunc gives you the same result.

Note: The actual difference come in to picture if you are passing the negative values as an argument to the function. For example,

b=FLoor(-5.45) would give you -6

b=Trunc(-5.45) would give you -5

Now you can decide which one to use.

If you are sure that you are not passing negative values, then use either

If you are not sure, then use TRUNC.

Hope this clears the dilemma....

Thanks,

Babu Kilari

Edited by: Babu Kilari on May 7, 2009 9:15 AM

Edited by: Babu Kilari on May 7, 2009 9:18 AM

Read only

0 Likes
2,999

Thanks for CRYSTAL clear response Babu.

Its pretty much clear now...actually i am passing the months value to this which are coming in decimals just to take the value...so Months are always +ve i think either can work

Regards

sas

Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
2,999

This message was moderated.

Read only

0 Likes
2,999

>

> hi,

>

>

data : a type i value '1.765',
>           b type i,
>           c type i.
> split a at '.' into b c.
> write :/ b , c.

>

> Thanks and regards

That doesn't even syntax check!

"A" must be a character-like data object (data type C, N, D, T, or

STRING) field string).

Read only

0 Likes
2,999

Hi MAtt,

I regret posting that kind of a reply. I apologize for my mistake.

Read only

former_member222860
Active Contributor
0 Likes
2,999

Hi,

Check this

data: v_data1 type p decimals 3 value '12.860',
      v_char1 type char20,
      v_char2 type char20,
      v_char3 type char20.

write v_data1 to v_char1.

split v_char1 at '.' into v_char2 v_char3.

write:/ v_char2, v_char3.

In the above v_char2 holds the digit value

thanks\

Mahesh

Read only

Former Member
0 Likes
2,999

DATA: a(10) TYPE c ,

lv_num1(10) TYPE c,

lv_num2 TYPE c.

a = '12.12'.

SPLIT a AT '.' INTO lv_num1

lv_num2.

write: lv_num1.

Edited by: BrightSide on May 6, 2009 3:59 PM

Read only

Peranandam
Contributor
0 Likes
2,999

Hi,

it will resolve your issue

data: a type p decimals 2 value '8.65',

b type i.

b = TRUNC( a ).

Regards,

Peranandam