Saturday, March 9, 2013

OFMT - default awk output format - is "%.6g", from GNU Awk User's Guide

"5.4 Controlling Numeric Output with print
The built-in variable OFMT contains the default format specification that print uses with sprintf when it wants to convert a number to a string for printing. The default value of OFMT is "%.6g". The way print prints numbers can be changed by supplying different format specifications as the value of OFMT, as shown in the following example:

$ awk 'BEGIN {
> OFMT = "%.0f" # print numbers as integers (rounds)
> print 17.23, 17.54 }'
-| 17 18

According to the POSIX standard, awk's behavior is undefined if OFMT contains anything but a floating-point conversion specification. (d.c.)"

from The GNU Awk User's Guide

'via Blog this'

No comments:

Post a Comment