How to format the output using float in awk{printf}

Hi

I'm using awk to manipulate the data in the 6th field of the file xxx_yyy.hrv.

The sample data that is available in this field is given below
220731.7100000000000000

When i tried using this command
cat xxx_yyy.hrv | awk '{printf("%23.16f\n",$6*-1)}'

I get the output as -220731.7099999999991269
but i need the output as -220731.7100000000000000

Plz let me know on the format that i should be using to retreive the desired output.
Thanks!!!

awk '{printf("%23.16f\n", sprintf("%.2f", $6-1))}' xxx_yyy.hrv

Hi vgersh99!!!

I tried with command that you've given
awk '{printf("%23.16f\n", sprintf("%.2f", $6-1))}' xxx_yyy.hrv | head -5 | tail -1

but i get the output as
220730.7099999999991269

but i need the output to be
-220731.7100000000000000

My requirement is to multiply the 6th field value with -1, and my pbm is the value after the decimal point gets modified when it is multiplied.

Plz let me know for any other possibilities also.

Thanks!!!

nawk '{printf("%.2f%.14d\n", $6 * -1, 0)}' xxx_yyy.hrv

It Worked :slight_smile: !!!
Thanks a lot!!!