You are here

public static function Settings::formatPrice in Basic cart 8.0

Same name and namespace in other branches
  1. 8.6 src/Settings.php \Drupal\basic_cart\Settings::formatPrice()
  2. 8 src/Settings.php \Drupal\basic_cart\Settings::formatPrice()
  3. 8.2 src/Settings.php \Drupal\basic_cart\Settings::formatPrice()
  4. 8.3 src/Settings.php \Drupal\basic_cart\Settings::formatPrice()
  5. 8.4 src/Settings.php \Drupal\basic_cart\Settings::formatPrice()
  6. 8.5 src/Settings.php \Drupal\basic_cart\Settings::formatPrice()

Formats the input $price in the desired format.

Parameters

float $price: The price in the raw format.

Return value

$price The price in the custom format.

1 call to Settings::formatPrice()
Utility::getCartData in src/Utility.php

File

src/Settings.php, line 44

Class

Settings

Namespace

Drupal\basic_cart

Code

public static function formatPrice($price) {
  $config = self::cartSettings();
  $format = $config
    ->get('price_format');
  $currency = $config
    ->get('currency');
  $price = (double) $price;
  switch ($format) {
    case 0:
      $price = number_format($price, 2, ',', ' ') . ' ' . $currency;
      break;
    case 1:
      $price = number_format($price, 2, '.', ' ') . ' ' . $currency;
      break;
    case 2:
      $price = number_format($price, 2, '.', ',') . ' ' . $currency;
      break;
    case 3:
      $price = number_format($price, 2, ',', '.') . ' ' . $currency;
      break;
    case 4:
      $price = $currency . ' ' . number_format($price, 2, ',', ' ');
      break;
    case 5:
      $price = $currency . ' ' . number_format($price, 2, '.', ' ');
      break;
    case 6:
      $price = $currency . ' ' . number_format($price, 2, '.', ',');
      break;
    case 7:
      $price = $currency . ' ' . number_format($price, 2, ',', '.');
      break;
    default:
      $price = number_format($price, 2, ',', ' ') . ' ' . $currency;
      break;
  }
  return $price;
}