Format Percentage

Format a decimal number as a percentage with configurable precision.

Code

Utilities
printf "%.${decimals}f%%\n" "$(echo "$num * 100" | bc)"

Parameters

The decimal number (0-1).

Decimal places to show.

Server

More Bash Snippets