Subbeh
Subbeh

Reputation: 924

Awk change decimal formats

I've got a file containing decimal values formatted like 9.85E-4. How can I make awk format this value to 0.000985?

Upvotes: 0

Views: 100

Answers (1)

fedorqui
fedorqui

Reputation: 289535

Use printf with the %f option:

awk '{printf "%f\n", your_field .... }' file

Example

$ cat a
9.85E-4
23
$ awk '{printf "%f\n", $1}' a
0.000985
23.000000

From The GNU Awk User’s Guide # 5.5.2 Format-Control Letters:

%e, %E

Print a number in scientific (exponential) notation.

%f

Print a number in floating-point notation

Upvotes: 4

Related Questions