PHP code example of mezinn / number

1. Go to this page and download the library: Download mezinn/number library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mezinn / number example snippets


use mezinn\number\NumberFactory;

$numberFactory = new NumberFactory();
$number = $numberFactory->create('123.45');

use mezinn\number\Number;
use mezinn\number\NumberCalculator;
use mezinn\number\NumberFactory;

$numberFactory = new NumberFactory();
$numberCalculator = new NumberCalculator($numberFactory);

$a = $numberFactory->create('123.45');
$b = $numberFactory->create('67.89');
$c = $numberFactory->create('2');

$result = $numberCalculator->add($a, $b);
// $result is a Number instance representing the value 191.34

$result = $numberCalculator->subtract($a, $b);
// $result is a Number instance representing the value 55.56

$result = $numberCalculator->multiply($a, $b);
// $result is a Number instance representing the value 8381.02

$result = $numberCalculator->divide($a, $b);
// $result is a Number instance representing the value 1.81

$result = $numberCalculator->pow($a, $c);
// $result is a Number instance representing the value 15239.90

$result = $numberCalculator->sqrt($a);
// $result is a Number instance representing the value 11.11


use mezinn\number\Number;
use mezinn\number\NumberFactory;
use mezinn\number\NumberFormatter;

$numberFactory = new NumberFactory();
$numberFormatter = new NumberFormatter();

$number = $numberFactory->create('-1234567.89');
$formatted = $numberFormatter->format($number, ',', true);
// $formatted is '-1,234,567.89'