LukePOLO\LaraCart\LaraCart::formatMoney PHP Method

formatMoney() public static method

Formats the number into a money format based on the locale and international formats.
public static formatMoney ( $number, $locale = null, $internationalFormat = null, $format = true ) : string
$number
$locale
$internationalFormat
$format
return string
    public static function formatMoney($number, $locale = null, $internationalFormat = null, $format = true)
    {
        $number = number_format($number, 2, '.', '');
        if ($format) {
            setlocale(LC_MONETARY, null);
            setlocale(LC_MONETARY, empty($locale) ? config('laracart.locale', 'en_US.UTF-8') : $locale);
            if (empty($internationalFormat) === true) {
                $internationalFormat = config('laracart.international_format', false);
            }
            $number = money_format($internationalFormat ? '%i' : '%n', $number);
        }
        return $number;
    }

Usage Example

Beispiel #1
0
 /**
  * Gets the formatted price
  *
  * @param bool|true $format
  *
  * @return string
  */
 public function price($format = true)
 {
     $price = $this->price;
     if (isset($this->items)) {
         foreach ($this->items as $item) {
             $price += $item->price(false);
         }
     }
     return LaraCart::formatMoney($price, $this->locale, $this->internationalFormat, $format);
 }
All Usage Examples Of LukePOLO\LaraCart\LaraCart::formatMoney