Format Currency

Format a number as currency with the appropriate symbol and separators.

Code

Utilities
case "$currency" in USD) sym='$';; EUR) sym='€';; GBP) sym='£';; *) sym="$currency";; esac
printf "%s%'.2f\n" "$sym" "$num"

Parameters

The number to format.

Currency code (USD, EUR, GBP, etc.).

Locale for formatting.

Server

More Bash Snippets