Files
kupshop/class/smarty_plugins/modifier.format_float.php
2025-08-02 16:30:27 +02:00

31 lines
529 B
PHP

<?php
/**
* Smarty plugin.
*/
/**
* Smarty {format_price} function plugin.
*
* @param float $value Float to format
* @param int $decimals number of decimal places
*
* @return string
*/
function smarty_modifier_format_float($value, $decimals = 2)
{
if ($value == '') {
return '';
}
$value = (float) $value;
$decimals = (int) $decimals;
$value = number_format($value, abs($decimals), ',', ' ');
if ($decimals < 0) {
$value = trim($value, '0,');
}
return $value;
}