# Help with decimal points

**URL:** <https://community.unix.com/t/help-with-decimal-points/345001>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [July 31, 2014, 11:51am UTC](https://community.unix.com/t/help-with-decimal-points/345001 "2014-07-31T11:51:47Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![sxiong](https://community.unix.com/letter_avatar/sxiong/32/6_22734026db12803ebb3e059622ac3534.png) [@sxiong](https://community.unix.com/u/sxiong)\
**Post date:** [July 31, 2014, 11:51am UTC](https://community.unix.com/t/help-with-decimal-points/345001/1 "2014-07-31T11:51:47Z")

</div>

Hi All,

I would like to set decimal point to 16 in the following bash script but it has syntax error at }:

```nohighlight
awk '{printf"%.16e", (a<500,a++,$1/(a*1.1212121212121229e-02))}' input.dat >output.dat

```

How may I set it in the correct way please? Thank you very much!

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_22734026db12803ebb3e059622ac3534.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [July 31, 2014, 12:10pm UTC](https://community.unix.com/t/help-with-decimal-points/345001/2 "2014-07-31T12:10:43Z")

</div>

I'm pretty sure your construct `(a<500,a++,$1/(a*1.1212121212121229e-02))` is not understood by awk. What be your intention?

---

<div class="post-metadata">

**Author:** ![Don\_Cragun](https://community.unix.com/user_avatar/community.unix.com/don_cragun/32/2682_2.png) [@Don\_Cragun](https://community.unix.com/u/Don_Cragun)\
**Post date:** [July 31, 2014, 12:13pm UTC](https://community.unix.com/t/help-with-decimal-points/345001/3 "2014-07-31T12:13:02Z")

</div>

Please explain in English what this `awk` script is supposed to do. I can make a few wild guesses, but none of them make any sense to me.

Then note that `awk` uses double precision floating point arithmetic (which gives you about 15-17 significant digits on individual values). Rounding errors may significantly reduce the precision of your results depending on the ranges of values being multiplied and divided.

What does the data in input.dat look like?

---

<div class="post-metadata">

**Author:** ![sxiong](https://community.unix.com/letter_avatar/sxiong/32/6_22734026db12803ebb3e059622ac3534.png) [@sxiong](https://community.unix.com/u/sxiong)\
**Post date:** [July 31, 2014, 12:26pm UTC](https://community.unix.com/t/help-with-decimal-points/345001/4 "2014-07-31T12:26:30Z")

</div>

Thanks for your kind replies. I want to divide the data in my input.dat by a times a constant as a goes from 1 to 499. I used

```nohighlight
awk '{print (a<500,a++,$1/(a*1.121212121212121229e-02))}' input.dat >output.dat

```

and got the desired values with 6 digits although the code is far from perfect. Here is part of the input:

```nohighlight
1.0805574801665273e+01
1.0631847858835727e+01
1.0461243720756954e+01
1.0293701484862595e+01
1.0129161486782039e+01

```

and output:

```nohighlight
1 0 963.74
1 1 474.123
1 2 311.01
1 3 229.522
1 4 180.682

```

So I'd like to find a way to set the decimal point of output data to 16. Would you please shed light on the problem? Thanks a lot!

---

<div class="post-metadata">

**Author:** ![MadeInGermany](https://community.unix.com/letter_avatar/madeingermany/32/6_22734026db12803ebb3e059622ac3534.png) [@MadeInGermany](https://community.unix.com/u/MadeInGermany)\
**Post date:** [July 31, 2014, 12:41pm UTC](https://community.unix.com/t/help-with-decimal-points/345001/5 "2014-07-31T12:41:00Z")

</div>

Print two integers and one floating point?

```nohighlight
awk '{printf "%d %d %.16f\n",(a<500),a++,$1/(a*1.121212121212121229e-02)}' input.dat

```

You get exponential notation if you change `f` to `e` .

---

<div class="post-metadata">

**Author:** ![sxiong](https://community.unix.com/letter_avatar/sxiong/32/6_22734026db12803ebb3e059622ac3534.png) [@sxiong](https://community.unix.com/u/sxiong)\
**Post date:** [July 31, 2014, 12:44pm UTC](https://community.unix.com/t/help-with-decimal-points/345001/6 "2014-07-31T12:44:53Z")

</div>

That is exactly what I want. Thank you very much! I forgot I have three columns in the output... Thanks again!

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_22734026db12803ebb3e059622ac3534.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [July 31, 2014, 12:49pm UTC](https://community.unix.com/t/help-with-decimal-points/345001/7 "2014-07-31T12:49:51Z")

</div>

Please use code tags as required by forum rules!

How about

```nohighlight
awk '{print a<500,a++,$1/(a*1.121212121212121229e-02)}' OFMT="%.16g" file
1 0 963.7404552836596
1 1 474.1229450561879
1 2 311.0099484549365
1 3 229.5217222976119
1 4 180.6823400344904

```
