Created
June 26, 2025 07:28
-
-
Save theapache64/1f5b5d1d1c5bb20f9ed98235fd2de6d9 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 | |
diff=$(echo "scale=4 ; $1 - $2" | bc) | |
diffPerc=$(echo "scale=4 ; $diff / $2 * 100" | bc) | |
printf "Difference of %s and %s are %.2f%%\n" "$1" "$2" "$diffPerc" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment