负浮点数未使用awk或sort正确排序 [英] Negative floating point numbers are not sorted correctly using awk or sort

查看:83
本文介绍了负浮点数未使用awk或sort正确排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因,负浮点数与awksort的比较在我的机器上似乎已被破坏.似乎是-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆