示例#1
0
 /**
  * Return currency amount formatted for display
  *
  * @return StringType
  */
 public function display()
 {
     $formatter = new \NumberFormatter($this->locale->get(), \NumberFormatter::CURRENCY);
     $formatter->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $this->symbol->get());
     $formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $this->precision->get());
     return new StringType(sprintf($this->displayFormat, $formatter->format($this->getAsFloat())));
 }
示例#2
0
 /**
  * Constructor - check for gmp support
  *
  * @param mixed $value
  * @throws GmpNotSupportedException
  */
 public function __construct($value)
 {
     if (empty(self::$gmpInstalled) || $this->checkGmpInstalled()) {
         self::$gmpInstalled = true;
     } else {
         throw new GmpNotSupportedException();
     }
     parent::__construct($value);
 }
 * @copyright Ashley Kitson, UK, 2014
 * @licence GPL V3 or later : http://www.gnu.org/licenses/gpl.html
 */
include "../vendor/autoload.php";
use Chippyash\Type\Number\IntType;
//PHP 5.3
//$nn = [];
//for ($x=1; $x<101; $x++) {
//    $nn[] = $x;
//}
//PHP 5.4+
$nn = range(1, 100);
$nn[] = 16449741;
//just a big number
foreach ($nn as $ni) {
    $n = new IntType($ni);
    echo "n = {$n}\n";
    //find the prime factors
    $pFactors = $n->primeFactors();
    echo "= ";
    $line = "√(";
    foreach ($pFactors as $prime => $exponent) {
        for ($e = 0; $e < $exponent; $e++) {
            $line .= "{$prime} x ";
        }
    }
    $line = rtrim($line, 'x ');
    echo "{$line})\n";
    //reduce
    $left = [];
    $right = [];
示例#4
0
 /**
  * @dataProvider factors
  */
 public function testPrimeFactorsReturnsAnArrayOfFactorsOfTheNumber($n, array $ignore, array $pFactors)
 {
     $i = new IntType($n);
     //unwrap the factors - phpUnit does not pass keys in!
     $pf = array();
     foreach ($pFactors as $factor) {
         $k = key($factor);
         $pf[$k] = $factor[$k];
     }
     $this->assertEquals($pf, $i->primeFactors());
 }