Four decimal places with awk

i have a script in which awk prints "($2-1700)/10000"
and the answer is -0.07,but i want the answer in 4 decimal places.
that is -0.0700.
How can i sue awk to get my results in four decimal places

In the States we sue for more numbers on the left of the decimal place... :smiley:

But in awk you can use printf(), most likely

printf(%.4f\n),"-0.07001"

Use the printf() function for the output. The format string with which to format the output follows the same rules as the C-function "printf()". In your case:

printf "%-7.4f\n" "1.2345"

I hope this helps.

bakunin

If you have multiple instances where that precision is required, perhaps a better solution would be to set OFMT to "%.4f". Then you can simply use a plain "print x" statement.

Regards,
Alister

it worked thanks to you all