示例#1
0
 /**
  * Convert the start value to it's highest whole unit.
  * Accespts an optional precision for how many significant digits
  * to retain
  *
  * @param int|null $precision
  * @return float
  */
 public function toBest($precision = null)
 {
     $fromUnit = UnitResolver::resolve($this->from);
     $base = $this->getBase() == 2 ? 1024 : 1000;
     $converted = $this->start;
     while ($converted >= 1) {
         $fromUnit++;
         $result = $this->div($this->start, pow($base, $fromUnit), $precision);
         if ($result <= 1) {
             return $converted;
         }
         $converted = $result;
     }
     return $converted;
 }
示例#2
0
 /**
  * @expectedException \Nomnom\UnitNotFoundException
  * @expectedExceptionMessage Unit "XB" not found
  */
 public function test_unknown_metric_throws_exception()
 {
     UnitResolver::resolve("XB");
 }