public static function PHPExcel_Calculation_Engineering::CONVERTUOM in Loft Data Grids 7.2
Same name and namespace in other branches
- 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Engineering.php \PHPExcel_Calculation_Engineering::CONVERTUOM()
* CONVERTUOM * * Converts a number from one measurement system to another. * For example, CONVERT can translate a table of distances in miles to a table of distances * in kilometers. * * Excel Function: * CONVERT(value,fromUOM,toUOM) * *
Parameters
float $value The value in fromUOM to convert.: * @param string $fromUOM The units for value. * @param string $toUOM The units for the result. * * @return float
File
- vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Calculation/ Engineering.php, line 2421
Class
- PHPExcel_Calculation_Engineering
- PHPExcel_Calculation_Engineering
Code
public static function CONVERTUOM($value, $fromUOM, $toUOM) {
$value = PHPExcel_Calculation_Functions::flattenSingleValue($value);
$fromUOM = PHPExcel_Calculation_Functions::flattenSingleValue($fromUOM);
$toUOM = PHPExcel_Calculation_Functions::flattenSingleValue($toUOM);
if (!is_numeric($value)) {
return PHPExcel_Calculation_Functions::VALUE();
}
$fromMultiplier = 1.0;
if (isset(self::$_conversionUnits[$fromUOM])) {
$unitGroup1 = self::$_conversionUnits[$fromUOM]['Group'];
}
else {
$fromMultiplier = substr($fromUOM, 0, 1);
$fromUOM = substr($fromUOM, 1);
if (isset(self::$_conversionMultipliers[$fromMultiplier])) {
$fromMultiplier = self::$_conversionMultipliers[$fromMultiplier]['multiplier'];
}
else {
return PHPExcel_Calculation_Functions::NA();
}
if (isset(self::$_conversionUnits[$fromUOM]) && self::$_conversionUnits[$fromUOM]['AllowPrefix']) {
$unitGroup1 = self::$_conversionUnits[$fromUOM]['Group'];
}
else {
return PHPExcel_Calculation_Functions::NA();
}
}
$value *= $fromMultiplier;
$toMultiplier = 1.0;
if (isset(self::$_conversionUnits[$toUOM])) {
$unitGroup2 = self::$_conversionUnits[$toUOM]['Group'];
}
else {
$toMultiplier = substr($toUOM, 0, 1);
$toUOM = substr($toUOM, 1);
if (isset(self::$_conversionMultipliers[$toMultiplier])) {
$toMultiplier = self::$_conversionMultipliers[$toMultiplier]['multiplier'];
}
else {
return PHPExcel_Calculation_Functions::NA();
}
if (isset(self::$_conversionUnits[$toUOM]) && self::$_conversionUnits[$toUOM]['AllowPrefix']) {
$unitGroup2 = self::$_conversionUnits[$toUOM]['Group'];
}
else {
return PHPExcel_Calculation_Functions::NA();
}
}
if ($unitGroup1 != $unitGroup2) {
return PHPExcel_Calculation_Functions::NA();
}
if ($fromUOM == $toUOM && $fromMultiplier == $toMultiplier) {
// We've already factored $fromMultiplier into the value, so we need
// to reverse it again
return $value / $fromMultiplier;
}
elseif ($unitGroup1 == 'Temperature') {
if ($fromUOM == 'F' || $fromUOM == 'fah') {
if ($toUOM == 'F' || $toUOM == 'fah') {
return $value;
}
else {
$value = ($value - 32) / 1.8;
if ($toUOM == 'K' || $toUOM == 'kel') {
$value += 273.15;
}
return $value;
}
}
elseif (($fromUOM == 'K' || $fromUOM == 'kel') && ($toUOM == 'K' || $toUOM == 'kel')) {
return $value;
}
elseif (($fromUOM == 'C' || $fromUOM == 'cel') && ($toUOM == 'C' || $toUOM == 'cel')) {
return $value;
}
if ($toUOM == 'F' || $toUOM == 'fah') {
if ($fromUOM == 'K' || $fromUOM == 'kel') {
$value -= 273.15;
}
return $value * 1.8 + 32;
}
if ($toUOM == 'C' || $toUOM == 'cel') {
return $value - 273.15;
}
return $value + 273.15;
}
return $value * self::$_unitConversions[$unitGroup1][$fromUOM][$toUOM] / $toMultiplier;
}