1

I know bash doesn't support long division, but here it goes. I looked up a bash work-around to giving me a supposed numeric value for the division. For example, this is what I got:

#!/bin/bash
SMALL_NUMBER=4
LARGE_NUMBER=56100

MATH_PROBLEM=$((100*$SMALL_NUMBER/$LARGE_NUMBER))
echo $MATH_PROBLEM

I execute the code and the output is always 0. I thought multiplying the expression by 100 would fix this but apparently not. Can someone tell me what is going on with this?

user202729
  • 2,782
  • 3
  • 19
  • 30
ryekayo
  • 2,153
  • 3
  • 21
  • 48

1 Answers1

3

Bash only does integers, not floats; you must delegate the task to a tool such as bc

py9
  • 561
  • 4
  • 14