Format a number as currency with the appropriate symbol and separators.
Code
Utilities$symbols = ['USD' => '$', 'EUR' => '€', 'GBP' => '£', 'JPY' => '¥'];
$symbol = $symbols[$currency] ?? $currency;
return $symbol . number_format($num, 2);Parameters
The number to format.
Currency code (USD, EUR, GBP, etc.).
Locale for formatting.
Server
More PHP Snippets
Binary to Decimal
Convert a binary string representation to its decimal number equivalent.
Bytes to Human Readable
Convert bytes to human readable format (KB, MB, GB, etc.) for file sizes.
Calculate Median
Calculate the median value of an array of numbers.
Calculate Mode
Find the most frequent value(s) in an array.
Calculate Percentile
Calculate the nth percentile of an array using linear interpolation.
Celsius to Fahrenheit
Convert temperature from Celsius to Fahrenheit using the standard formula.