Created
March 22, 2017 23:05
-
-
Save 84adam/c08008900bb4f7f0d51ad6bfc663f75b to your computer and use it in GitHub Desktop.
Calculate rounded percentage in bash using bc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment