Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active April 2, 2023 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dacr/a75da1f701b976bdd9417f0e44eb0acc to your computer and use it in GitHub Desktop.
Save dacr/a75da1f701b976bdd9417f0e44eb0acc to your computer and use it in GitHub Desktop.
bash printf example with float rounding / published by https://github.com/dacr/code-examples-manager #1118db89-6fbd-4610-98b2-0374d345d60a/e382519546869ce10c35b2463bcb4e0822833cf1
## summary : bash printf example with float rounding
## keywords : bash, printf, compute, @testable
## publish : gist
## authors : David Crosson
## license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
## id : 1118db89-6fbd-4610-98b2-0374d345d60a
## created-on : 2019-10-16T13:35:40Z
## managed-by : https://github.com/dacr/code-examples-manager
## run-with : sh $file
export TOTAL=236
export TOTAL_MN=$(echo "$TOTAL*5" | bc )
export TOTAL_H=$(echo "$TOTAL_MN/60" | bc -l)
export TOTAL_D=$(echo "$TOTAL_MN/60/6" | bc -l)
export LANG=us
export LC_NUMERIC="en_US.UTF-8"
printf "Total: %d units, %.1f minutes, %.1f hours, %.1f days\n" $TOTAL $TOTAL_MN $TOTAL_H $TOTAL_D
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment