Exemple #1
0
 public function testNumberDivideThenMultiply()
 {
     $price = new Number('3.99');
     $divPrice = $price->divide('1.2');
     $this->assertEquals(3.33, $divPrice->getNumber());
     $mulPrice = $divPrice->multiply('1.2');
     $this->assertEquals(3.99, $mulPrice->getNumber());
 }
 /**
  * @return \Thelia\Math\Number
  * @throws \Thelia\CurrencyConverter\Exception\CurrencyNotFoundException if the `from` currency is not support
  */
 private function retrieveRateFactor()
 {
     if ($this->from === 'EUR') {
         return new Number(1);
     }
     $rateStr = $this->getRateFromFeed($this->from);
     $rate = new Number($rateStr);
     $base = new Number(1);
     return $base->divide($rate);
 }
 /**
  * @return \Thelia\Math\Number
  * @throws \Thelia\CurrencyConverter\Exception\CurrencyNotFoundException if the `from` currency is not support
  */
 private function retrieveRateFactor()
 {
     $rateFactor = false;
     if ($this->from === 'EUR') {
         $rateFactor = new Number(1);
     } else {
         // Find the exchange rate for this currency
         foreach ($this->data->Cube as $last) {
             $code = strtoupper((string) $last["currency"]);
             if ($code === $this->from) {
                 // Get the rate factor
                 $rate = new Number((string) $last['rate']);
                 $base = new Number(1);
                 $rateFactor = $base->divide($rate);
                 echo "\nretrieveRateFactor() :  last['rate'] = " . $last['rate'];
                 echo "\nretrieveRateFactor() :  rate number = " . print_r($rate, 1);
                 echo "\nretrieveRateFactor() :  base = " . print_r($base, 1);
                 echo "\nretrieveRateFactor() :  rateFactor = " . print_r($rateFactor, 1);
             }
         }
     }
     if (false === $rateFactor) {
         throw new CurrencyNotFoundException($this->from);
     }
     return $rateFactor;
 }