# printf respects locale, may have to set `LC_NUMERIC=C` to get internationally agreed behaviour. # format placeholder syntax %[parameter][flags][width][.precision][length]type ## parameter `n$`, specify parameter position, missing in shells and gnu coreutils `printf`. ## flags - `-`: left align - `+`: sign positive numbers as well - ` `: don't sign positive numbers but prepend space - `0`: in conjunction w/ `width`, pad w/ zeroes instead of spaces - `#`: `g`: include trailing zeroes, `e`, `f`, `g`: include decimal point, `o`, `x`: prepend w/ `0` or `0x` ## width minimum width of output. allows dynamic value w/ `*`. ## precision maximum limit, for floating point round digitsafter decimal point, for string truncate. allows dynamic value w/ `*`. following examples behave same. printf '%.2f' 42.239 printf '%.*f' 2 42.239 ## length can be omitted. ## type - `d`, `i`: signed int as decimal, behave same - `u`: unsigned int as decimal - `f`, `F`: double as fixed point, uses lower- or uppercase on inf and NaN - `e`, `E`: exponent notation, `1 == 1.000000e+00`, `10 == 1.000000e+01` - `g`, `G`: shorten, `f` or `e` whichever applies best, omit traling zeroes - `x`, `X`: unsigned int as hex, use lower- or uppercase - `o`: unsigned int as octal - `s`: string - `c`: char - `a`, `A`: double in hex