You are here

public static function PHPExcel_Calculation_Financial::DOLLARFR in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php \PHPExcel_Calculation_Financial::DOLLARFR()

* DOLLARFR * * Converts a dollar price expressed as a decimal number into a dollar price * expressed as a fraction. * Fractional dollar numbers are sometimes used for security prices. * * Excel Function: * DOLLARFR(decimal_dollar,fraction) * * @access public * @category Financial Functions *

Parameters

float $decimal_dollar Decimal Dollar: * @param integer $fraction Fraction * @return float

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php, line 1115

Class

PHPExcel_Calculation_Financial
PHPExcel_Calculation_Financial

Code

public static function DOLLARFR($decimal_dollar = Null, $fraction = 0) {
  $decimal_dollar = PHPExcel_Calculation_Functions::flattenSingleValue($decimal_dollar);
  $fraction = (int) PHPExcel_Calculation_Functions::flattenSingleValue($fraction);

  // Validate parameters
  if (is_null($decimal_dollar) || $fraction < 0) {
    return PHPExcel_Calculation_Functions::NaN();
  }
  if ($fraction == 0) {
    return PHPExcel_Calculation_Functions::DIV0();
  }
  $dollars = floor($decimal_dollar);
  $cents = fmod($decimal_dollar, 1);
  $cents *= $fraction;
  $cents *= pow(10, -ceil(log10($fraction)));
  return $dollars + $cents;
}