负浮点数未使用awk或sort正确排序 [英] Negative floating point numbers are not sorted correctly using awk or sort
问题描述
由于某些原因,负浮点数与awk
和sort
的比较在我的机器上似乎已被破坏.似乎是-0.1 < -0.2
.
For some reason, comparisons of negative floating point numbers with awk
and sort
seem to be broken on my machine. It seems that -0.1 < -0.2
.
当我尝试排序时
0.2
-0.1
-0.2
0.1
0
使用sort -n test.dat
,我得到
-0.1
-0.2
0
0.1
0.2
代替
-0.2
-0.1
0
0.1
0.2
我怎么了?
推荐答案
答案:您是法国人!
用法语,小数点是逗号(,
)而不是点(.
).您需要用逗号替换圆点或更改语言环境.
In french, the decimal point is a comma (,
) and not a dot (.
). You need to either replace the dots with commas or change your locale.
尝试LC_NUMERIC=us_EN.UTF-8 sort -n test.dat
,您应该会得到预期的结果.
Try LC_NUMERIC=us_EN.UTF-8 sort -n test.dat
and you should get the expected result.
供您参考,LC_NUMERIC
是一个环境变量,其中包含用于格式化非货币数字的语言环境.
For your information, LC_NUMERIC
is an environment variable that contains the locale to use for formatting non-monetary numbers.
这篇关于负浮点数未使用awk或sort正确排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!