Created
June 26, 2025 07:31
-
-
Save theapache64/bad0f9bd9407dc47241e8d32646ec9e8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
pw() { | |
result=$(echo "scale=4 ; $1 / $2 * 100" | bc) | |
printf "%s is %.2f%% of %s\n" "$1" "$result" "$2" | |
if (( $(echo "$1 < $2" | bc -l) )) | |
then | |
diff=$(echo "scale=4 ; $2 - $1" | bc) | |
diffPerc=$(echo "scale=4 ; $diff / $2 * 100" | bc) | |
printf "%s is a %.2f%% decrease of %s\n" "$1" "$diffPerc" "$2" | |
else | |
diff=$(echo "scale=4 ; $1 - $2" | bc) | |
diffPerc=$(echo "scale=4 ; $diff / $2 * 100" | bc) | |
printf "%s is a %.2f%% increase of %s\n" "$1" "$diffPerc" "$2" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment