简体   繁体   中英

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

and this one

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

gives 8.9000000000000004e+00

Notice the zero at the left side in 11. This result difference is ok?

Thanks

This is because 011 is parsed as an octal value. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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