-4

I need a script that converts a number from bytes to GB (not GiB) and rounds the result to 2 decimal places. How would I go about doing this?

Thanks.

0

1 Answer 1

3
$ n=1832985293598283    
$ echo  $(echo "scale=2; $n/1000000000"  | bc -l)
1832985.29
$ 

Tells bc to calculate $n divided by a billion, with two decimals. bc should be available almost everywhere.

2
  • But how would I pass an output of a script to this? Dec 29, 2017 at 17:41
  • By substituting $n with the output value of the script. For instance by storing the output of the script in a variable.
    – vidarlo
    Dec 29, 2017 at 17:45

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