Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does AWK understand number written in in E notation?

Tags:

awk

I have a tab-separated file with several columns, where one column contains numbers written in a format like this

4.07794484177529E-293

I wonder if AWK understands this notation? I.e. I want to get only the lines where the numbers in that column are smaller than 0.1.

But I am not sure if AWK will understand what "4.07794484177529E-293" is - can it do arithmetic comparisons on this format?


1 Answers

Yes, to answer your question, awk does understand E notation.

You can confirm that by:

awk '{printf "%f\n", $1}' <<< "4.07794484177529E-3"
0.004078

In general, awk uses double-precision floating-point numbers to represent all numeric values. This gives you the range between 1.7E–308 and 1.7E+308 to work with, so you are okay with 4.07794484177529E-293

Aside: you can specify how to format the print of floating point number with awk as follows:

awk '{printf "%5.8f\n", $1}' <<< "1.2345678901234556E+4"
12345.67890123

Explanation:

  • %5.8f is what formats the float
  • the 5 part before the . specifies how many digits to print before the decimal apoint
  • the 8 part after the . specifies how many digits to print after the decimal point
like image 75
sampson-chen Avatar answered Oct 28 '25 04:10

sampson-chen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!