Anda dapat mencoba ini:
$ awk 'BEGIN{printf "%3.0f\n", 3.6}'
4
Opsi format kami memiliki dua bagian:
3
: berarti output akan diisi hingga 3 karakter.
.0f
: berarti output tidak akan memiliki presisi, yang berarti dibulatkan.
Dari man awk
, Anda dapat melihat detail lebih lanjut:
width The field should be padded to this width. The field is normally padded
with spaces. If the 0 flag has been used, it is padded with zeroes.
.prec A number that specifies the precision to use when printing. For the %e,
%E, %f and %F, formats, this specifies the number of digits you want
printed to the right of the decimal point. For the %g, and %G formats,
it specifies the maximum number of significant digits. For the %d, %o,
%i, %u, %x, and %X formats, it specifies the minimum number of digits to
print. For %s, it specifies the maximum number of characters from the
string that should be printed.
/dev/null
perlu?