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

Doubt in type p

Former Member
0 Likes
1,405

Dear experts,

I have declared the variable as

Data betrg type p decimal 3.

But for this it is showing the wrong ouput

e.g:-

1/30 = 0.033333333333

but it is taking only 0.033

so afer multipication value is decresing from the orginl value

similaily

8/30 = 0.26666666666666666

but it is taking as .267

and i m not getting the actual value.

What type of declaration I will do to get the actual value.

Regards

Ansuman Parhi

Dear experts,

I have declared the variable as

Data betrg type p decimal 3.

But for this it is showing the wrong ouput

e.g:-

1/30 = 0.033333333333

but it is taking only 0.033

so afer multipication value is decresing from the orginl value

similaily

8/30 = 0.26666666666666666

but it is taking as .267

and i m not getting the actual value.

What type of declaration I will do to get the actual value.

Regards

Ansuman Parhi

9 REPLIES 9
Read only

peter_ruiz2
Active Contributor
0 Likes
1,276

hi,

This is because you have declare a variable with the P DECIMALS 3 meaning it will only accept 3 decimal places. try changing the data type to P DECIMALS 11 to be able to achieve your desired output.

regards,

Peter

Read only

Former Member
0 Likes
1,276

Hi

Please write in this way

data xyz type p decimal 8 .

Now it will take upto 8 decimal places .

~hitesh

Read only

Former Member
0 Likes
1,276

Hi,

since ur specifying the decimal precision , it is rounding of to your req no of decimals.if you want to have more precision , increase the no of decimals and do a offset moving to another variable.

Raj D

Read only

vinod_vemuru2
Active Contributor
0 Likes
1,276

Hi Ansuman,

As others told increase the number of decimals.

Other thing i understand from ur query is why

0.033333333333 as 0.033 and 0.26666666666666666 as 0.027.

This is because of rounding is happening.

Here 6666 is GT 5 that is why rounding to 7

3333 is LT 5 so rounding to 3 itself.

Thanks,

Vinod.

Read only

0 Likes
1,276

Dear Vinod,

Even if I am increasing the decimal place it is not giving me the actual value.

I have increased it to 11 places and still it is giving me 214.999 and for other cases it is giving me 1064.666666.But my desired outpu must be 215 and 1064.67.

So is there any other way for getting the actual value.

Regards

Ansuman

Read only

0 Likes
1,276

Hi,

U can use ROUND function for that.

Read only

0 Likes
1,276

Hi ,

from you post i understand that you req a precision of 2 decimals.

like if it is 214.9999 you want it as 215.00 and it it is 1064.66666 you want it to be 1064.67.

So specify the length as 2 instead of 3 for p data type.

Hope this solves your problem'

Raj D

Read only

Former Member
0 Likes
1,276

hi,

i think this is due to your decimal precision

if you define data like this:

data:   num type p decimals 3.

of course you will get only 3 decimals.

so if you want to get more decimals, you should increase the decimal precision.

Read only

Former Member
0 Likes
1,276

hi anshumaan,

as u told that ur query is giving wrong output. it is due to the declaration part where u are declaring the data type as BETRG TYPE P DECIMAL 3. since u have put 3 after DECIMAL so it will give the value upto 3 decimal places with rounding off the last digit. So if u want to increase the accuracy u will have to do like

BETRG TYPE P DECIMAL 10 as much places u want upto but still it will round off.

thanx

nitesh