1

I have a data file consists of rows with numeric data. The example of numeric data is 4053.45677771. When I perform arithmetic operation with nawk like;

 nawk -F, '{print $1*1000}' data > data_2

numeric values in data_2 file looks with exponential and precision is lost like; 4.05346e+06 How can I multiply with 1000 without exponential usage and precision lost?

deepblue_86
  • 1,194

1 Answers1

3

Use printf for finer control over the output:

$ echo 4053.45677771 | nawk '{printf "%f\n",$1*1000}'
4053456.777710

So, for your example:

nawk -F, '{printf "%f\n",$1*1000}' data > data_2

You can also stick to print if you set the OFMT variable (POSIX.1-2008 supports it):

$ echo 4053.45677771 | nawk -vOFMT='%f' '{print $1*1000}'  
4053456.777710
muru
  • 197,895
  • 55
  • 485
  • 740