You are here

function _invoice_round_and_format_money in Invoice 7

Same name and namespace in other branches
  1. 6 invoice_helpers.inc \_invoice_round_and_format_money()

Returns a rounded and formatted number according to the locale set on the invoice settings page

Parameters

mixed $number:

integer $precision:

Return value

mixed

7 calls to _invoice_round_and_format_money()
invoice_delete_item in ./invoice_ajax.inc
Delete an invoice item
invoice_form in ./invoice_form.inc
Implements hook_form()
invoice_invoices in ./invoice.module
Overview of all invoices
invoice_load in ./invoice.module
Implements hook_load()
invoice_save_item in ./invoice_ajax.inc
Add an invoice item

... See full list

File

./invoice_helpers.inc, line 242
Invoice module

Code

function _invoice_round_and_format_money($number, $precision = 2) {

  // If the precision is larger than 2 and the rounded number has no more than 2 decimals,
  // then still only 2 decimals will be displayed.
  $rounded_number = _invoice_round($number, $precision);

  // Count the amount of decimals
  $exp = explode('.', $rounded_number);
  $decimals = isset($exp[1]) ? strlen($exp[1]) : 0;

  // Display at least 2 decimals
  if ($decimals < 2) {
    $decimals = 2;
  }

  // Money format the rounded number
  return $rounded_and_formatted_number = _invoice_format_money($rounded_number, $decimals);
}