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

Division Value Display problem

Former Member
0 Likes
2,560

Hi experts,

I have problem while calculating fraction value. For instance A/B = some value.

I have to print the value as it comes with 2/3 decimal values without rounding. If I deduce the length of decimal values to 2/3 in data type "Packed", it is rounding. For example it rounds 0.0995 as 0.100. But I need only 0.099 only.

If I copy the first 3 decimals in string, it is also giving problem. For example, for some divisions I am getting result as 9.955..........E-02. So, Here I could not copy the decimals to string also. So, Can u give me a solution. Is there any funtion module to get the value as it is with 2/3 decimal values.

<removed_by_moderator>

Venkat, IBM

Edited by: Julius Bussche on Feb 2, 2009 11:15 AM

1 ACCEPTED SOLUTION
Read only

GauthamV
Active Contributor
0 Likes
1,702

declare it as type p decimals 3.


data : var type p decimals 3.

data : a type i value 2,
       b type i value 3.

var = a / b.

write : var.

11 REPLIES 11
Read only

GauthamV
Active Contributor
0 Likes
1,703

declare it as type p decimals 3.


data : var type p decimals 3.

data : a type i value 2,
       b type i value 3.

var = a / b.

write : var.

Read only

Former Member
0 Likes
1,702

If I use P with decimal 3 it is rounding some digits. Without rounding I need 3 decimals.

Venkat, IBM

Read only

GauthamV
Active Contributor
0 Likes
1,702

For example it rounds 0.0995 as 0.100. But I need only 0.099 only.

This is your requirement in first post .

Read only

Former Member
0 Likes
1,702

A and B values are taken from tables ( NETWR and KAWRT ) , so we can not have decimals for that and I wan to have in result only

Read only

Former Member
0 Likes
1,702

>

> if you are also under crush in your organisation, do your work rather than advising all in the forum.

No, I'm neither in "Crush" nor have any crush I meant you should not use any words like U'rgent blah blah its against of forum rules.

Thanks for understanding.

Back to Topic:

>

> A and B values are taken from tables ( NETWR and KAWRT ) , so we can not have decimals for that and I wan to have in result only

So what you may do,Just store your result in type P decimal 3 type variable and print this variable.

Like:

Result type p decimal 3.

Result = NETWR / KAWRT .

print Result.

Do some work around this.

Amit.

Read only

Former Member
0 Likes
1,702

Hi expert,

I already used with decimal 3. It is rounding the value which I don't want. Anyhow I tried with decimal 14, which is maximum and assigned first 3 decimal values in a string and I printed in smartform. I got solved. However, Thank you for your kindness. Thank you for your time and consideration. If I have used any hurting words, please forgive me.

Venkat

Read only

Former Member
0 Likes
1,702
which is maximum and assigned first 3 decimal values in a string 
and I printed in smartform. I got solved.

Yes Decimal 3 was your only concern "in resultant variable".

If I have used any hurting words, please forgive me.

No need of apologies.

Also, you didn't use any offended words in your language except U'rgent in your Question Also I never mind your kind of responses.

I appreciate your learning and response.

P.S. Glad to see your problem solved though you were in urged

Cheers,

Amit.

Read only

faisalatsap
Active Contributor
0 Likes
1,702

Hi,

Please Test the following Sample Code May help you in this way.

data: a TYPE p DECIMALS 3,
      b TYPE p DECIMALS 3,
      div TYPE p DECIMALS 3.

a = 2.
b = 3.

DIV = a / b.

WRITE: div. " .667 here.

Please Reply if Else Requirment.

Kind Regards,

Faisal

Read only

Former Member
0 Likes
1,702

>

> Please reply immediately. I will be thankful to you if I complete this today itself. I am in urge.

Possibely,We guys also in crunch.

Venkat, IBM

Although,rules of posting not having the instructions regarding this, But i personally believe you should not mention company name with your Signature or Name unless IBM is your Family name.

Thank you.

Read only

0 Likes
1,702

sorry sir, Your helpful tip was not the remedy for my problem. You might have got more points in forum. But none is ABAP library in the world. Anyhow thank you for your reply and if you are also under crush in your organisation, do your work rather than advising all in the forum. I am a fresher and I think there is no problem if i don't know in this new world. Anyhow I learnt a lesson from u. Thank you.

Venkat

Read only

Former Member
0 Likes
1,702

I used packed data type with decimals 14, which is maximum for P and first 3 fractions I copied to string and I got the desired value, inwhich no rounding I found.

Thank you