on 10-13-2009 11:49 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
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
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.