You are here

public static function PHPExcel_Calculation_MathTrig::ROMAN in Loft Data Grids 6.2

Same name and namespace in other branches
  1. 7.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/MathTrig.php \PHPExcel_Calculation_MathTrig::ROMAN()

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/MathTrig.php, line 893

Class

PHPExcel_Calculation_MathTrig
PHPExcel_Calculation_MathTrig

Code

public static function ROMAN($aValue, $style = 0) {
  $aValue = PHPExcel_Calculation_Functions::flattenSingleValue($aValue);
  $style = is_null($style) ? 0 : (int) PHPExcel_Calculation_Functions::flattenSingleValue($style);
  if (!is_numeric($aValue) || $aValue < 0 || $aValue >= 4000) {
    return PHPExcel_Calculation_Functions::VALUE();
  }
  $aValue = (int) $aValue;
  if ($aValue == 0) {
    return '';
  }
  $mill = array(
    '',
    'M',
    'MM',
    'MMM',
    'MMMM',
    'MMMMM',
  );
  $cent = array(
    '',
    'C',
    'CC',
    'CCC',
    'CD',
    'D',
    'DC',
    'DCC',
    'DCCC',
    'CM',
  );
  $tens = array(
    '',
    'X',
    'XX',
    'XXX',
    'XL',
    'L',
    'LX',
    'LXX',
    'LXXX',
    'XC',
  );
  $ones = array(
    '',
    'I',
    'II',
    'III',
    'IV',
    'V',
    'VI',
    'VII',
    'VIII',
    'IX',
  );
  $roman = '';
  while ($aValue > 5999) {
    $roman .= 'M';
    $aValue -= 1000;
  }
  $m = self::_romanCut($aValue, 1000);
  $aValue %= 1000;
  $c = self::_romanCut($aValue, 100);
  $aValue %= 100;
  $t = self::_romanCut($aValue, 10);
  $aValue %= 10;
  return $roman . $mill[$m] . $cent[$c] . $tens[$t] . $ones[$aValue];
}