Exemplo n.º 1
0
 /**
  * Convert between formats
  *
  * @author Marien den Besten
  * @param integer $from_measure
  * @param string $from_unit
  * @param string $to_unit
  * @param integer $round
  * @return type
  */
 private function convert($from_measure, $from_unit, $to_unit, $round = null)
 {
     if ($to_unit == $from_unit) {
         //return if no conversion is needed
         return !is_null($round) ? (string) round($from_measure, $round) : (string) $from_measure;
     }
     if (!array_key_exists($from_unit, $this->conversion_table) || !array_key_exists($to_unit, $this->conversion_table[$from_unit])) {
         return 0;
     }
     //set precision
     $round = is_null($round) ? 50 : $round;
     return Utils::removeBcTrailingZeros(bcmul($from_measure, $this->conversion_table[$from_unit][$to_unit], $round));
 }