public static function Settings::formatPrice in Basic cart 8.0
Same name and namespace in other branches
- 8.6 src/Settings.php \Drupal\basic_cart\Settings::formatPrice()
- 8 src/Settings.php \Drupal\basic_cart\Settings::formatPrice()
- 8.2 src/Settings.php \Drupal\basic_cart\Settings::formatPrice()
- 8.3 src/Settings.php \Drupal\basic_cart\Settings::formatPrice()
- 8.4 src/Settings.php \Drupal\basic_cart\Settings::formatPrice()
- 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
Namespace
Drupal\basic_cartCode
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;
}