简体   繁体   English

awk中的左零会导致不同的结果

[英]Left zeros in awk lead to different results

I notice the follow sentence 我注意到了以下句子

 echo | awk '{OFMT="%.16e";CONVFMT="%.16e";print 10.-0.1*011}'

gives 9.0999999999999996e+00 给出9.0999999999999996e + 00

and this one 还有这个

 echo | awk '{OFMT="%.16e";CONVFMT="%.16e";print 10.-0.1*11}'

gives 8.9000000000000004e+00 给出8.9000000000000004e + 00

Notice the zero at the left side in 11. This result difference is ok? 注意11中左侧的零点。这个结果差异还可以吗?

Thanks 谢谢

This is because 011 is parsed as an octal value. 这是因为011被解析为八进制值。 If you do 如果你这样做

$ echo | awk '{OFMT="%.16e";CONVFMT="%.16e";print 10.-0.1*9}'
9.0999999999999996e+00

You get the same result, because 9 in decimal is 011 in octal 你得到相同的结果,因为十进制中的9是八进制的011

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM