nick34992
2/19/2017 - 6:42 PM

Bash: echo: scale, bc: numerical fractions decimal places

Bash: echo: scale, bc: numerical fractions decimal places

#!/bin/bash

echo "scale=4;1/16" | bc
echo "scale=3;1/8" | bc
echo "scale=4;3/16" | bc
echo "scale=2;1/4" | bc
echo "scale=4;5/16" | bc
echo "scale=3;3/8" | bc
echo "scale=4;7/16" | bc
echo "scale=1;1/2" | bc
echo "scale=4;9/16" | bc
echo "scale=3;5/8" | bc
echo "scale=4;11/16" | bc
echo "scale=2;3/4" | bc
echo "scale=4;13/16" | bc
echo "scale=3;7/8" | bc
echo "scale=4;15/16" | bc
echo "scale=0;1" | bc

# .0625
# .125
# .1875
# .25
# .3125
# .375
# .4375
# .5
# .5625
# .625
# .6875
# .75
# .8125
# .875
# .9375
# 1
#
# https://ss64.com/bash/bc.html