# print decimal values

**URL:** <https://community.unix.com/t/print-decimal-values/244539>\
**Category:** Shell Programming and Scripting\
**Created:** [July 14, 2009, 12:45am UTC](https://community.unix.com/t/print-decimal-values/244539 "2009-07-14T00:45:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![repinementer](https://community.unix.com/letter_avatar/repinementer/32/5_5575768a8748004e209b776fc1b2916d.png) [@repinementer](https://community.unix.com/u/repinementer)\
**Post date:** [July 14, 2009, 12:45am UTC](https://community.unix.com/t/print-decimal-values/244539/1 "2009-07-14T00:45:39Z")

</div>

Hi guys I'm trying to print average of 2 columns.

awk '{print ($1+$2)/2}' file.txt

Its printing average but not giving decimal values

its giving 3.05521e+08 instead of 305521....

I tried %f to print float values but not quiet connected

Could you help plz:confused:

---

<div class="post-metadata">

**Author:** ![agn](https://community.unix.com/letter_avatar/agn/32/5_5575768a8748004e209b776fc1b2916d.png) [@agn](https://community.unix.com/u/agn)\
**Post date:** [July 14, 2009, 12:48am UTC](https://community.unix.com/t/print-decimal-values/244539/2 "2009-07-14T00:48:42Z")

</div>

```nohighlight
awk '{printf "%f\n", ($1+$2)/2 }' file.txt

```

doesn't work ?

---

<div class="post-metadata">

**Author:** ![repinementer](https://community.unix.com/letter_avatar/repinementer/32/5_5575768a8748004e209b776fc1b2916d.png) [@repinementer](https://community.unix.com/u/repinementer)\
**Post date:** [July 14, 2009, 12:54am UTC](https://community.unix.com/t/print-decimal-values/244539/3 "2009-07-14T00:54:31Z")

</div>

No  
Its giving but not accurately  
all values ending either with .5000.. or .00000....

like  
135603981.500000  
135604080.000000  
135604672.500000

---

<div class="post-metadata">

**Author:** ![rakeshawasthi](https://community.unix.com/user_avatar/community.unix.com/rakeshawasthi/32/224_2.png) [@rakeshawasthi](https://community.unix.com/u/rakeshawasthi)\
**Post date:** [July 14, 2009, 1:06am UTC](https://community.unix.com/t/print-decimal-values/244539/4 "2009-07-14T01:06:04Z")

</div>

May be that is correct... what is your sample input?

---

<div class="post-metadata">

**Author:** ![ryandegreat25](https://community.unix.com/letter_avatar/ryandegreat25/32/5_5575768a8748004e209b776fc1b2916d.png) [@ryandegreat25](https://community.unix.com/u/ryandegreat25)\
**Post date:** [July 14, 2009, 1:14am UTC](https://community.unix.com/t/print-decimal-values/244539/5 "2009-07-14T01:14:48Z")

</div>

yes, maybe that is correct, maybe you just need to format it to 1 or 2 decimal places instead

---

<div class="post-metadata">

**Author:** ![repinementer](https://community.unix.com/letter_avatar/repinementer/32/5_5575768a8748004e209b776fc1b2916d.png) [@repinementer](https://community.unix.com/u/repinementer)\
**Post date:** [July 14, 2009, 1:18am UTC](https://community.unix.com/t/print-decimal-values/244539/6 "2009-07-14T01:18:15Z")

</div>

Yep thanx  
really helpful
