You are here

function uc_store_price_handler_format in Ubercart 6.2

Default price handler formatter; formats the price using the store currency display settings.

3 string references to 'uc_store_price_handler_format'
uc_price_settings_form in uc_store/uc_store.admin.inc
Form for enabling/weighting price alterers and selecting a price formatter.
uc_store_uc_price_handler in uc_store/includes/uc_price.inc
Implements hook_uc_price_handler().
_uc_price_get_handlers in uc_store/includes/uc_price.inc
Return an array of price handler data.

File

uc_store/includes/uc_price.inc, line 285
Price handling functions and hooks.

Code

function uc_store_price_handler_format($price, $options) {
  $output = '';

  // If the value is less than the minimum precision, zero it.
  if ($options['prec'] > 0 && abs($price) < 1 / pow(10, $options['prec'])) {
    $price = 0;
  }

  // Force the price to a positive value and add a negative sign if necessary.
  if ($price < 0) {
    $price = abs($price);
    $output .= '-';
  }

  // Add the currency sign first if specified.
  if ($options['sign'] && !$options['sign_after']) {
    $output .= $options['sign'];
  }

  // Format the number, like 1234.567 => 1,234.57
  $output .= number_format($price, $options['prec'], $options['dec'], $options['thou']);

  // Add the currency sign last if specified.
  if ($options['sign'] && $options['sign_after']) {
    $output .= $options['sign'];
  }
  return $output;
}