-3

This question is an exact duplicate of:

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?

marked as duplicate by Jeff Schaller, Jesse_b, G-Man, dhag, andcoz Feb 12 '18 at 17:18

This question was marked as an exact duplicate of an existing question.

  • 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

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.

  • its not work when I put the variable inside bc -l <<< 'scale = 1; $NUM / 1024' – jango Feb 12 '18 at 14:35
  • Variables are expanded in double quotes, not single quotes. – choroba Feb 12 '18 at 14:38
  • @jango: Please read the following: Quoting – Jesse_b Feb 12 '18 at 14:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.