PHP code example of pamil / rounder

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

    

pamil / rounder example snippets


use Pamil\Rounder\Rounder;
use Pamil\Rounder\BasicRounder;

$rounder = new BasicRounder();

// Use new API
$rounder->roundHalfUp(12.15, 1); // 12.2
$rounder->roundHalfUp(-12.315, 2); // -12.31

// Or old round API
$rounder->round(24.5); // 25
$rounder->round(24.5, 0, Rounder::ROUND_DOWN); // 24

// You can even use old PHP_ROUND_* constants
// Warning: as mentioned above, PHP_ROUND_HALF_UP and
// PHP_ROUND_HALF_DOWN have been badly named, so they
// aren't equivalent for Rounder::ROUND_HALF_UP and
// Rounder::ROUND_HALF_DOWN. They are 100% back compatibile,
// $rounder->round() returns the same values round() will return.

$rounder->round(23.5, 0, PHP_ROUND_HALF_EVEN); // 24
$rounder->round(22.5, 0, PHP_ROUND_HALF_EVEN); // 22