Skip to content
Advertisement

Convert Scientific Notation into decimal number using bash [closed]

I need to convert 1.22661727081984E+002 to 122.661727081984 using shell script. I have tried it using the below command:

echo "+1.22661727081984E+002" | awk -F"E" 'BEGIN{OFMT="%10.10f"} {print $1 * (10 ^ $2)}' 

output:

122.6617270820

It is giving me the output but rounding off the last 4 digits.

I need the output without rounding off the result.

Advertisement

Answer

Using Bash’s printf:

$ printf "%.14fn" 1.22661727081984E+002
122.66172708198400
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement