<?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;
}
