1

1 gwei = 0.000000001 ether

There's a program that displays only 156489673002 (156 gwei), which is 0.000000156489673002 ether.

But how to, in Bash, calculate how many ether is 156489673002 (so the output is 0.000000156489673002)?

  • 2
    You use, instead of bash, a language which can do fractional arithmetic: `bc`, `awk` and `zsh` for instance, though if you need high precision, `bc` is probably the best choice. Other good alternatives are i.e. Ruby, Perl, Python and others. – user1934428 Nov 29 '21 at 08:11

1 Answers1

1

You can get the result with awk:

echo "0.1 0.1" | awk '{printf "%.18f\n", 156489673002 / 1000000000000000000}'

or

echo "0.1 0.1" | awk '{printf "%.18f\n", 156489673002 / 1e18}'
David Ranieri
  • 39,972
  • 7
  • 52
  • 94