private static function PHPExcel_Style_NumberFormat::_formatAsFraction in Loft Data Grids 7.2
Same name and namespace in other branches
- 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Style/NumberFormat.php \PHPExcel_Style_NumberFormat::_formatAsFraction()
1 call to PHPExcel_Style_NumberFormat::_formatAsFraction()
- 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 476
Class
- PHPExcel_Style_NumberFormat
- PHPExcel_Style_NumberFormat
Code
private static function _formatAsFraction(&$value, &$format) {
$sign = $value < 0 ? '-' : '';
$integerPart = floor(abs($value));
$decimalPart = trim(fmod(abs($value), 1), '0.');
$decimalLength = strlen($decimalPart);
$decimalDivisor = pow(10, $decimalLength);
$GCD = PHPExcel_Calculation_MathTrig::GCD($decimalPart, $decimalDivisor);
$adjustedDecimalPart = $decimalPart / $GCD;
$adjustedDecimalDivisor = $decimalDivisor / $GCD;
if (strpos($format, '0') !== false || strpos($format, '#') !== false || substr($format, 0, 3) == '? ?') {
if ($integerPart == 0) {
$integerPart = '';
}
$value = "{$sign}{$integerPart} {$adjustedDecimalPart}/{$adjustedDecimalDivisor}";
}
else {
$adjustedDecimalPart += $integerPart * $adjustedDecimalDivisor;
$value = "{$sign}{$adjustedDecimalPart}/{$adjustedDecimalDivisor}";
}
}