- 论坛徽章:
- 2
|
明白了,好像与locale有关
- $ LC_ALL="en_US" awk 'BEGIN{printf("%'"'"'.2f\n",123456789.12)}'
- 123,456,789.12
复制代码
https://www.gnu.org/software/gaw ... rmat-Modifiers.html
A single quote or apostrophe character is a POSIX extension to ISO C. It indicates that the integer part of a floating-point value, or the entire part of an integer decimal value, should have a thousands-separator character in it. This only works in locales that support such characters. For example:
$ cat thousands.awk Show source program
-| BEGIN { printf "%'d\n", 1234567 }
$ LC_ALL=C gawk -f thousands.awk
-| 1234567 Results in "C" locale
$ LC_ALL=en_US.UTF-8 gawk -f thousands.awk
-| 1,234,567 Results in US English UTF locale |
|