_batch_api_percentage

  1. drupal
    1. drupal7
Versionen
drupal7 _batch_api_percentage($total, $current)

Helper function for _batch_process(): returns the formatted percentage.

Übergabeparameter

$total The total number of operations.

$current The number of the current operation.

Rückgabewert

The properly formatted percentage, as a string. We output percentages using the correct number of decimal places so that we never print "100%" until we are finished, but we also never print more decimal places than are meaningful.

▾ 2 functions call _batch_api_percentage()

BatchAPIPercentagesTestCase::testBatchAPIPercentages in modules/simpletest/tests/batch.test
Test the _batch_api_percentage() function with the data stored in the testCases class variable.
_batch_process in includes/batch.inc
Process sets in a batch.

Code

includes/batch.inc, line 340

<?php
function _batch_api_percentage($total, $current) {
  if (!$total || $total == $current) {
    // If $total doesn't evaluate as true or is equal to the current set, then
    // we're finished, and we can return "100".
    $percentage = "100";
  }
  else {
    // We add a new digit at 200, 2000, etc. (since, for example, 199/200
    // would round up to 100% if we didn't).
    $decimal_places = max(0, floor(log10($total / 2.0)) - 1);
    $percentage = sprintf('%01.' . $decimal_places . 'f', round($current / $total * 100, $decimal_places));
  }
  return $percentage;
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen