You are here

private static function PHPExcel_Style_NumberFormat::_formatAsPercentage in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Style/NumberFormat.php \PHPExcel_Style_NumberFormat::_formatAsPercentage()
1 call to PHPExcel_Style_NumberFormat::_formatAsPercentage()
PHPExcel_Style_NumberFormat::toFormattedString in vendor/phpoffice/phpexcel/Classes/PHPExcel/Style/NumberFormat.php
* Convert a value in a pre-defined format to a PHP string * *

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Style/NumberFormat.php, line 458

Class

PHPExcel_Style_NumberFormat
PHPExcel_Style_NumberFormat

Code

private static function _formatAsPercentage(&$value, &$format) {
  if ($format === self::FORMAT_PERCENTAGE) {
    $value = round(100 * $value, 0) . '%';
  }
  else {
    if (preg_match('/\\.[#0]+/i', $format, $m)) {
      $s = substr($m[0], 0, 1) . (strlen($m[0]) - 1);
      $format = str_replace($m[0], $s, $format);
    }
    if (preg_match('/^[#0]+/', $format, $m)) {
      $format = str_replace($m[0], strlen($m[0]), $format);
    }
    $format = '%' . str_replace('%', 'f%%', $format);
    $value = sprintf($format, 100 * $value);
  }
}