Quantcast
Channel: Recent Gists from 84adam
Viewing all articles
Browse latest Browse all 34

Calculate rounded percentage in bash using bc

$
0
0
gistfile1.txt
CODE:
x=<FIRSTNUM>; y=<SECONDNUM>; printf $(echo "scale=4; $x/$y * 100" | bc | cut -d . -f 1)%%
EXAMPLE:
x=55; y=85; printf $(echo "scale=4; $x/$y * 100" | bc | cut -d . -f 1)%%
OUTPUT:
64%

Viewing all articles
Browse latest Browse all 34

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>