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

Issue : Variable Decimal Rounding

Former Member
0 Likes
1,343

Hi Gurus,

I have the variable P_DATA with value 75468.275.

P_DATE is of type OIJ_ACTQTY.

I am doing an arthematic operation P_DATA = P_DATA / 10.

But the value of P_DATA is becoming 7546.828

I don't want rounding to happen.

QUESTION : How can we restrict Rounding ? I want value to be 7546.827.

Avi

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,235

I guess there is a more elegant Version on how to do this, but following will work.

Make yourself a local variable wit decimals 4.

Now do your calculation into the new local variable.

Slope this local variable to another new variable of type char. Then you can tranfer it back to another char variable using offset.

Now you can transfer it back to your probably type p field.

10 REPLIES 10
Read only

Former Member
0 Likes
1,234

Hi

That means you want the result rounded off to default, so I think you need to store the result in a variable with 4 decimals and then move the rounded result in a variable with 3 decimals

Max

Read only

0 Likes
1,234

then move the rounded result in a variable with 3 decimals

Hi Max,

This will still round it.

A character variable of size 17 will be usefull

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,234

Its because OIJ_ACTQTY is of decimals 3 and cannot accomodate 4 decimals, so it rounds off.


data:p_data type OIJ_ACTQTY,
     p_p type p decimals 4,
     p_char type char17.
     p_data = '75468.275'.
     p_p = p_data / 10.   or   p_char = p_data / 10.

Read only

roberto_vacca2
Active Contributor
0 Likes
1,234

Hi...

Pass your value to HR_ROUND_NUMBER.. If you use rounding type "space" you get your number without any rounding.. 10,556=> 10,55 for example leaving '6' alone

hope to help...

Read only

roberto_vacca2
Active Contributor
0 Likes
1,234

...anyway there's also this function module ROUND

passing SIGN = space, you should gain your result..

Read only

Former Member
0 Likes
1,236

I guess there is a more elegant Version on how to do this, but following will work.

Make yourself a local variable wit decimals 4.

Now do your calculation into the new local variable.

Slope this local variable to another new variable of type char. Then you can tranfer it back to another char variable using offset.

Now you can transfer it back to your probably type p field.

Read only

0 Likes
1,234

Question was asked before in forum and i gave sort of the same solution as now:

gv1 = '75468.275'.
write: / gv1.
gv1 = gv1 * 100.
gv1 = trunc( gv1 ).
gv1 = gv1 / 1000.
write: / gv1.

Read only

0 Likes
1,234

Thanks .... multiplying and truncating did the trick.

Read only

0 Likes
1,234

>

> Thanks .... multiplying and truncating did the trick.

Would expect a thanks from Avi.. but hey.. you're welcome!

Read only

Former Member
0 Likes
1,234

Take a variable of type f for calculation purpose and also take a variable type p with 3 decimal places.

For example.

I have the variable P_DATA with value 75468.275.

p_var1 type f.

p_var2(15) type p decimals 3.

p_var1 = p_data / 10.

Move value of variable p_var1 to p_var2.