Ross
2023-05-07 21:36:04 UTC
I am using awk for some basic calculations and want to force my output to be in scientific notation. I am using OFMT="%.15e" to accomplish this. On most machines, I get the expected output:
$ awk 'BEGIN { OFMT = "%.15e"; print 4.483923595133619e+29 / 1000 }'
4.483923595133619e+26
But a version of awk on my cluster gives:
$ awk --version | head --lines=2
GNU Awk 4.0.2
Copyright (C) 1989, 1991-2012 Free Software Foundation.
$ awk 'BEGIN { OFMT = "%.15e"; print 4.483923595133619e+29 / 1000 }'
448392359513361882871234560
Why is this version/configuration of awk not outputting to scientific notation as requested? How can I portably get my desired result (4.483923595133619e+26)?
(This question was originally posted to stackexchange at https://stackoverflow.com/questions/76187717/awk-not-outputting-in-scientific-notation-despite-e but it didn't get much attention and I was directed here instead.)
$ awk 'BEGIN { OFMT = "%.15e"; print 4.483923595133619e+29 / 1000 }'
4.483923595133619e+26
But a version of awk on my cluster gives:
$ awk --version | head --lines=2
GNU Awk 4.0.2
Copyright (C) 1989, 1991-2012 Free Software Foundation.
$ awk 'BEGIN { OFMT = "%.15e"; print 4.483923595133619e+29 / 1000 }'
448392359513361882871234560
Why is this version/configuration of awk not outputting to scientific notation as requested? How can I portably get my desired result (4.483923595133619e+26)?
(This question was originally posted to stackexchange at https://stackoverflow.com/questions/76187717/awk-not-outputting-in-scientific-notation-despite-e but it didn't get much attention and I was directed here instead.)