cancel
Showing results for 
Search instead for 
Did you mean: 

How to round the fractional value into the next highest value?

Former Member
0 Kudos

Hi Experts,

I have field where user will enter fractional values. But it has to be rounded classically.

I mean if the user enter Greater than or = 0.5 value should be rounded as 1

If i t is lessthan or equal to 0.49 then it should be rounded as 0.

I tried with "Ceil" "Floor" and "round" nothing is working for me.

Thanks in Advance,

Dharani

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member40425
Contributor
0 Kudos

Hi,

Use following code.

data: var type F value '4.5',
      frac type I,
          result type I.

frac = frac( var ).

if frac eq 0.
  result = floor( var ).
  else.
    result  = ceil( var ).
    ENDIF.

Revert back in case of any problem.

Regards,

Rohit

Former Member
0 Kudos

hi ,

use DATA variable of type I ( integer) for the same

refer this thread :

for a similar kind of requirement , refer the replies in that , u wud get it

regards,

amit

Edited by: amit saini on Oct 13, 2009 12:52 PM

Former Member
0 Kudos

Use int for this.

data : lv type I.

lv = str.

now lv will contain the rounded off value only.

here str is the value which you want to round off to neareest no.

if str = .49 then lv = 1.

Edited by: Saurav Mago on Oct 13, 2009 4:20 PM

Former Member
0 Kudos

Hi ,

Thanks for thge input.

Filed (which suppose to be rounded off) is referring to the database table field type.

SO can't declare a variable as integerand assign to this.

Please adivce

Thanks in Advance,

Dharani

Former Member
0 Kudos

hi ,

ok fine , but in this case as well ,u can do like this :



 DATA : field type  ws_edit-anzhl ,
             int type I .
int = field

if u have referred tht thread in tht anzhl is also a field from database table

still u can assign integer type to it like above manner

I hope it wud help

rgds,

amit

Former Member
0 Kudos

hi,

Pls check my previous post.

If you declare a local variabl of type I and assign the field to be rounded off to this, then it would be rounded off and value will be stored in the local variable lv.

What is the issue you are getting ?

From lv , you can assign this value to any other field also.

i.e

If you want to assign it back to database field , then assign it from local variable lv.

I hope it would help.

Former Member
0 Kudos

Hi Experts,

I have tried with thebelow code,But stillmy problemis not solved.

lv type i.

lv = ws_edit-anzhl.

ws_edit-anzhl = lv.

ws_0014-anzhl = ws_edit-anzhl .

Thanks in Advance,

Dharani

Former Member
0 Kudos

hi,

Can you please debug this by puting a break point and checking what value is getting in lv.

Because for me its working fine.

I have tried like this :

data lv type I.

data an type anzhl.

an = '7.22' .

lv = an. now lv has 7.00 . If i change the value of an, like an = 7.8 then lv = 8.

Please check at your end once again using breakpoints.

Edited by: Saurav Mago on Oct 13, 2009 5:12 PM

Former Member
0 Kudos

hi

this is running for me

let me expalin u , wht I was doing in my piece of code


DATA : field type  ws_edit-anzhl ,
             int type I .
int = field

here anzhl is some field of the table , nw int is yet another data field to which I am assigning this value .

nw u ought to use this int variable's value in rest of ur method , wherever u wish . It contains the intefer value ( which is actually a round of value ) of my fraction .

pls test by breakpont , this is running f9 for me

regards,

amit