예제 #1
0
 public function testHandlesGracefullyTooPreciseValues1()
 {
     $a = new Decimal2('0.001');
     $this->assertEquals('0.00', strval($a));
     $b = new Decimal2('0.009');
     $this->assertEquals('0.01', strval($b));
     $this->assertEquals('0.01', strval(Decimal2::plus($a, $b)));
 }
예제 #2
0
 /**
  * Returns the sum 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 sum(array $decimals)
 {
     $ret = new Decimal2('0');
     foreach ($decimals as $d) {
         $ret = Decimal2::plus($ret, $d);
     }
     return $ret;
 }