Ibara, thanks for your remarks.
The rounding error is because the script evolved from using only whole non-fractional input to fractional input for drilling holes , like 1/4, 1/6, 1/8, 1/16.
In the metric system we have drill bit sizes ranging from 1, 1,5, 2, 3.5, 4, 4.5 mm and so on. When somebody recommends to use a 1/16" drill bit for a simple DIY drip irrigation system, I needed to see which of my metric drill bits is the best equivalent. Hence the 4 digit precision.
Code:
$ echo 'scale = 4; 25.4 / 16' | bc
1.5875
So here I would use a 1.5 mm drill bit and not a 2 mm which the normal rounding would tell me. At the end of the irrigation pipe you already have less pressure than at the beginning. So 1.5 mm would be the best choice.
Then I needed to convert PVC pipe diameters like 1-1/4". For my script to handle that I had to wrap the '1 + 1/4" inside parentheses to get the correct answer:
Code:
$ echo 'scale=4 ; 25.4 / 4 ' | bc
6.3500
$ echo 'scale=4 ; 6.35 + 25.4 ' | bc
31.75
# wrong!
$ echo 'scale=4; 1 + 1 / 4 * 25.4' | bc
7.3500
# correct
$ echo 'scale=4; (1 + 1 / 4) * 25.4' | bc
31.7500
This is close to the 32 mm PVC irrigation pipe that I can get here.
To prevent the 5/9 rounding issue, a multiplication of 5 * 25.4 and then a division by 9 would be another method:
Code:
$ echo 'scale = 4 ; 5 * 25.4 / 9' | bc
14.1111
This, however, requires parsing of the input.