-1

I want to convert 8874M to GIGA so I did this

  echo $(( 8874 / 1024 ))

but actually we get 8 ( while exactly results is 8.6 )

so what need to change in order to get the 8.6?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
jango
  • 403
  • 2
  • 13
  • 18
  • 3
    I'm downvoting this because you just asked virtually the same question 50 minutes ago and you must not have read any of the answers/comments from it. – jesse_b Feb 12 '18 at 14:28

1 Answers1

1

Bash doesn't do floating point arithmetics. Use bc -l instead:

bc -l <<< 'scale = 1; 8874 / 1024'

By setting scale to 1, you get the "exact" result 8.6, not the real exact result of 8.66601562500000000000.

choroba
  • 45,735
  • 7
  • 84
  • 110