public function format($value, $code = null, $include_symbol = true)
    {
        // Get default currency if one is not set
        $code = $code ?: $this->config('default');

        // Remove unnecessary characters
        $value = preg_replace('/[\s\',!]/', '', $value);

        // Check for a custom formatter
        if ($formatter = $this->getFormatter()) {
            return $formatter->format($value, $code);
        }

        // Get the measurement format
        $format = $this->getCurrencyProp($code, 'format');

        // Value Regex
        $valRegex = '/([0-9].*|)[0-9]/';

        // Match decimal and thousand separators
        preg_match_all('/[\s\',.!]/', $format, $separators);

        if ($thousand = array_get($separators, '0.0', null)) {
            if ($thousand == '!') {
                $thousand = '';
            }
        }

        $decimal = array_get($separators, '0.1', null);

        // Match format for decimals count
        preg_match($valRegex, $format, $valFormat);

        $valFormat = array_get($valFormat, 0, 0);

        // Count decimals length
        $decimals = $decimal ? strlen(substr(strrchr($valFormat, $decimal), 1)) : 0;

        // Do we have a negative value?
        if ($negative = $value < 0 ? '-' : '') {
            $value = $value * -1;
        }

        // Format the value
        $value = number_format($value, $decimals, $decimal, $thousand);

        // Apply the formatted measurement
        if ($include_symbol) {
            $value = preg_replace($valRegex, $value, $format);
        }

        // Return value
        return $negative . $value;
    }
public function format($value, $code = null, $include_symbol = true)
    {
        // Get default currency if one is not set
        $code = $code ?: $this->config('default');

        // Remove unnecessary characters
        $value = preg_replace('/[\s\',!]/', '', $value);

        // Check for a custom formatter
        if ($formatter = $this->getFormatter()) {
            return $formatter->format($value, $code);
        }

        // Get the measurement format
        $format = $this->getCurrencyProp($code, 'format');

        // Value Regex
        $valRegex = '/([0-9].*|)[0-9]/';

        // Match decimal and thousand separators
        preg_match_all('/[\s\',.!]/', $format, $separators);

        if ($thousand = array_get($separators, '0.0', null)) {
            if ($thousand == '!') {
                $thousand = '';
            }
        }

        $decimal = array_get($separators, '0.1', null);

        // Match format for decimals count
        preg_match($valRegex, $format, $valFormat);

        $valFormat = array_get($valFormat, 0, 0);

        // Count decimals length
        $decimals = $decimal ? strlen(substr(strrchr($valFormat, $decimal), 1)) : 0;

        // Do we have a negative value?
        if ($negative = $value < 0 ? '-' : '') {
            $value = $value * -1;
        }

        // Format the value
        $value = number_format($value, $decimals, $decimal, $thousand);

        // Apply the formatted measurement
        if ($include_symbol) {
            $value = preg_replace($valRegex, $value, $format);
        }

        // Return value
        return $negative . $value;
    }
public function format ( $ value , $ code = null , $ include_symbol = true ) { // Get default currency if one is not set
 $ code = $ code ? : $ this -> config ( 'default' ) ; // Remove unnecessary characters
 $ value = preg_replace ( '/[\s\',!]/' , '' , $ value ) ; // Check for a custom formatter
 if ( $ formatter = $ this -> getFormatter ( ) ) { return $ formatter -> format ( $ value , $ code ) ; } // Get the measurement format
 $ format = $ this -> getCurrencyProp ( $ code , 'format' ) ; // Value Regex
 $ valRegex = '/([0-9].*|)[0-9]/' ; // Match decimal and thousand separators
 preg_match_all ( '/[\s\',.!]/' , $ format , $ separators ) ; if ( $ thousand = array_get ( $ separators , '0.0' , null ) ) { if ( $ thousand == '!' ) { $ thousand = '' ; } } $ decimal = array_get ( $ separators , '0.1' , null ) ; // Match format for decimals count
 preg_match ( $ valRegex , $ format , $ valFormat ) ; $ valFormat = array_get ( $ valFormat , 0 , 0 ) ; // Count decimals length
 $ decimals = $ decimal ? strlen ( substr ( strrchr ( $ valFormat , $ decimal ) , 1 ) ) : 0 ; // Do we have a negative value?
 if ( $ negative = $ value < 0 ? '-' : '' ) { $ value = $ value * - 1 ; } // Format the value
 $ value = number_format ( $ value , $ decimals , $ decimal , $ thousand ) ; // Apply the formatted measurement
 if ( $ include_symbol ) { $ value = preg_replace ( $ valRegex , $ value , $ format ) ; } // Return value
 return $ negative . $ value ; }
Format the value into the desired currency.

@param float  $value
@param string $code
@param bool   $include_symbol

@return string
Format the value into the desired currency .