示例#1
0
 /**
  * @param Decimal2 $amount
  * @return string
  */
 public function format(Decimal2 $amount)
 {
     switch ($this->code) {
         case 'JPY':
             return self::separateThousands(strval($amount->integerValue()), ',');
         case 'EUR':
         case 'GBP':
             return self::separateThousands(strval($amount->integerValue()), '.') . ',' . substr(strval($amount), -2);
         case 'CHF':
         case 'USD':
             return self::separateThousands(strval($amount->integerValue()), ',') . '.' . substr(strval($amount), -2);
         default:
             return strval($amount);
     }
 }
 /**
  * @param Decimal2 $d
  * @param integer $int
  * @param integer $fraction
  * @param string $strRep
  */
 private function assertD($d, $int, $fraction, $strRep)
 {
     $this->assertEquals($int, $d->integerValue());
     $this->assertEquals($fraction, $d->fractionValue());
     $this->assertEquals($strRep, strval($d));
 }
示例#3
0
 /**
  * Returns the average of all the decimal numbers in the array.
  *
  * @param array $decimals The array of Decimal2 objects.
  *
  * @return Decimal2 or boolean false for an empty $decimals array.
  */
 public static function avg(array $decimals)
 {
     if (!count($decimals)) {
         return false;
     }
     return Decimal2::div(Decimal2::sum($decimals), new Decimal2(count($decimals)));
 }