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: 

chop off to decimals 1

Former Member
0 Kudos

hi all,

Could someone kindly tell me how to do "chop off" by any keyword or FM?

I want to do:

'3.15' result in '3.1'

'3.11' result in '3.1'

Thanks~

1 ACCEPTED SOLUTION

former_member598013
Active Contributor
0 Kudos

Hi Wenwen,

Below is the sample code. to chopoff the value..... just copy and paste it it will resolve your problem

&****************Reward Point if helpful**********&


REPORT  zcctest.


data: val(10) type c value '312.87'.
data: result(10) type c.
data: flag type i value 0.
data: count type i value -1.


DO 10 TIMES.
  COUNT = COUNT + 1.
  CONCATENATE RESULT VAL+COUNT(1) INTO RESULT.

  if flag = 1.
  exit.
  endif.
  IF VAL+COUNT(1) = '.'.
    FLAG = 1.
  ENDIF.
ENDDO.
write: result.

6 REPLIES 6

former_member181995
Active Contributor
0 Kudos

Use data:field type p decimal 1.

Amit.

0 Kudos

I tried your solution, but it round off.

DATA: x TYPE p DECIMALS 2 VALUE '3.15',

y TYPE p DECIMALS 1.

And I got y = 3.2...

Former Member
0 Kudos

hi ,

Try the following code:

data:

no1 type p decimals 2 value '31.13',

no2 type p decimals 1.

no2 = no1.

write no2.

regards,

Jaya Vani

former_member598013
Active Contributor
0 Kudos

Hi Wenwen,

Below is the sample code. to chopoff the value..... just copy and paste it it will resolve your problem

&****************Reward Point if helpful**********&


REPORT  zcctest.


data: val(10) type c value '312.87'.
data: result(10) type c.
data: flag type i value 0.
data: count type i value -1.


DO 10 TIMES.
  COUNT = COUNT + 1.
  CONCATENATE RESULT VAL+COUNT(1) INTO RESULT.

  if flag = 1.
  exit.
  endif.
  IF VAL+COUNT(1) = '.'.
    FLAG = 1.
  ENDIF.
ENDDO.
write: result.

0 Kudos

hi all,

Appreciate for all your response~

Former Member
0 Kudos

try this sample

data: p1 type p DECIMALS 2 VALUE '3.15'.

data: p2 type p DECIMALS 1.

p2 = p1 * 10.

p2 = floor( p2 ) / 10.

write:/ 'floor', p2.