Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:23
Show Gist options
  • Select an option

  • Save dacr/a75da1f701b976bdd9417f0e44eb0acc to your computer and use it in GitHub Desktop.

Select an option

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/dab25da3088d01d0fa8c08a5d120bdfda4556907
## summary : bash printf example with float rounding
## keywords : bash, printf, compute, @testable
## publish : gist
## authors : David Crosson
## license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
## 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