first commit
This commit is contained in:
30
class/smarty_plugins/modifier.format_float.php
Normal file
30
class/smarty_plugins/modifier.format_float.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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;
|
||||
}
|
||||
Reference in New Issue
Block a user