PHP code example of krak / money

1. Go to this page and download the library: Download krak/money 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/ */

    

krak / money example snippets




use Krak\Money;

$calc = Money\calc($precision = 2);
$res = $calc->add('1.00', '2.00');
$res = $calc->mul($res, 2);



interface Calculator {
    public function add($a, $b);
    public function sub($a, $b);
    public function mul($a, $b);
    public function div($a, $b);
    public function cmp($a, $b);
}



abstract class AbstractCalculator implements Calculator {
    public function sum(...$args);
    public function diff(...$args);
    public function quot(...$args);
    public function prod(...$args);
    /** returns the max value of the set */
    public function max(...$args);
    /** returns the min value of the set */
    public function min(...$args);
    /** returns true if $a < $b */
    public function lt($a, $b);
    /** returns true if $a <= $b */
    public function lte($a, $b);
    /** returns true if $a > $b */
    public function gt($a, $b);
    /** returns true if $a >= $b */
    public function gte($a, $b);
    /** returns true if $a == $b */
    public function eq($a, $b);
    /** returns true if $a != $b */
    public function neq($a, $b);

    abstract public function add($a, $b);
    abstract public function sub($a, $b);
    abstract public function mul($a, $b);
    abstract public function div($a, $b);
    abstract public function cmp($a, $b);
}