0

When I trying to parse html via curl+jq I see that where it see 0.0000123 it printing for example 1.23e-05.How can I convert this? Or if is so hard please write some sed or awk alternatives.

1
  • 1
    See similar question on stackoverflow, with alternative perl solution.
    – meuh
    Feb 13, 2018 at 9:30

2 Answers 2

3

with awk you can do like this :

$ echo 123.4567E-05 | awk '{printf "%5.8f\n", $1}'
0.00123457

%x.yf determines the output format you want to see.

Then, you you can use your curl ......pattern....| awk '{printf .........}'

1

Most printf implementations could do the conversion:

printf '%5.4f' 1e-5 ==> 0.0000
printf '%7.4f' 1.23e2 ==> 123.0000
printf '%7.5f' 1.2324558e-2 ==> 0.01232

$ echo 12.34567E-3 | awk '{printf "%5.10f\n", $1}'
0.0123456700

$ echo "123.56e-2" | perl -ne 'printf( "%03.7f\n", $_)'
1.2356000

$ cat php01.php
<?php
$number = 123.45678e1;
printf("%10.3f\n",$number);
?>
$ php php01.php 
  1234.568

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .