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

Rounding a float value.

Former Member
0 Likes
3,472

Hi Friends,

I am trying to round a float value.

Suppose the value is 1.6666666666666666E-01

I need the output as 1.67

I hve been using ROUND function module but it gives me 1.6700000000E-01

when I use Packed decimal it takes as 0.17

Any suggestions..

Thanks

Chaithanya

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,324

Multiple by 10?


REPORT  rich_0001.

data: f type f value '1.6666666666666666E-01'.
data: p type p decimals 2.

p = f * 10.

write:/ p.

Regards,

Rich Heilman

6 REPLIES 6
Read only

Former Member
0 Likes
1,324

You cannot get 1.67 from 1.6666666666666666E-01 because it is nothing but the value 1.6666666666666666 raised to the power of -1 which is 0.16666666666666 to whatever precision which when rounded will become 0.17 (just what you got using a packed decimal). There is nothing wrong in what you are getting.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,325

Multiple by 10?


REPORT  rich_0001.

data: f type f value '1.6666666666666666E-01'.
data: p type p decimals 2.

p = f * 10.

write:/ p.

Regards,

Rich Heilman

Read only

0 Likes
1,324

Hi Rich,

Thanks Rich. Thanks for the solution. It got solved.

You are becoming richer by getting more points....

Just kidding.

Have a nice day.

Thanks,

chaithanya K

Read only

0 Likes
1,324

Not sure if this is the best way to do this, not sure that it will always work for all values, but in this particular case it does, hence the reason for my "?" in my above response.

BTW, the points make me richer, which means more food for the hungry.

/people/mark.finnern/blog/2007/11/28/food-for-points

Regards,

Rich Heilman

Read only

0 Likes
1,324

So you just multiply any value to get the your answer? How is that correct? I think you are doing the wrong thing to assume that you should multiply by 10. Are you working in one of those user exits where the "fixed point arithmetic" attribute is not checked?

Read only

0 Likes
1,324

Hi Srinivas,

Thanks for your reply. Now this thread has become a Knowledge Sharing.

As Rich already mentioned it is not the best solution but for me it worked out.

I am not working in any User exits. I had a floating point value when printed using forms it took large value.

1.6666666666

So I needed to truncate it or round it up to 3 decimals. Hope you understood.

Thanks,

Chaithanya K

Edited by: chaithanya k on Jan 9, 2008 7:57 AM