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
  • 3,358
  • 3
  • 25
  • 36
ryekayo
  • 2,341
  • 3
  • 23
  • 51

1 Answers1

3

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

py9
  • 598
  • 5
  • 15