Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Question awk printf format for floating numbers

    Hi All,

    We have a requirement in awk wherein we need to print a floating number with given precision (say 4 decimals) but without rounding off. And also the output should always be 4 decimals with zero padding.

    Can anyone let me know how this can be achieved.

    The expected outputs for various scenarios are as below:

    Actual Value Expected Output
    ------------------- -------------------------
    2 2.0000
    178.67 178.6700
    356.32222 356.3222
    1234.56789 1234.5678

    thanks and regards

  2. #2
    This should do it:

    printf("%0.4f\n", var)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts