Find the answer to your Linux question:
Results 1 to 2 of 2
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 ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2005
    Posts
    2

    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
    Rajesh.R

  2. #2
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    This should do it:

    Code:
    printf("%0.4f\n", var)
    Regards

Posting Permissions

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