0.30000000000000004
0.30000000000000004 copied to clipboard
awk example is deceptive
$ awk --version | head -1
GNU Awk 5.1.1, API: 3.1 (GNU MPFR 4.1.0-p13, GNU MP 6.2.1)
The example indeed prints 0.3, but 0.1 + 0.2 != 0.3:
$ awk 'BEGIN { print 0.1 + 0.2 }'
0.3
$ awk 'BEGIN { print (0.1 + 0.2) == 0.3 }'
0
It's because
$ awk 'BEGIN { printf "%0.25f", 0.1 + 0.2 }'
0.3000000000000000444089210
$ awk 'BEGIN { printf "%0.25f", 0.3 }'
0.2999999999999999888977698