jnjxp/rinc

Round numbers to increments

0.1.0 2016-07-22 19:24 UTC

This package is auto-updated.

Last update: 2024-12-26 08:57:01 UTC


README

Round numbers to increments

Latest version Build Status Coverage Status Quality Score

Installation

composer require jnjxp/rinc

Usage

use Jnjxp\Rinc;

// Rounder
$roundTo = new Rinc\RoundTo;

echo $roundTo->nearest(1/4, 0.24);  // 0.25
echo $roundTo->next(1/4, 0.26);     // 0.5
echo $roundTo->previous(1/4, 0.46); // 0.25

// Increment
$quarter = new Rinc\Increment(1/4);
echo $quarter(0.24);           // 0.25 (same as nearest())
echo $quarter->nearest(0.24);  // 0.25
echo $quarter->next(0.26);     // 0.5
echo $quarter->previous(0.46); // 0.25

// Named Convenience Constructors
$eighth  = Rinc\Increment::eighth();  // new Rinc\Increment(1/8)
$quarter = Rinc\Increment::quarter(); // new Rinc\Increment(1/4)
$half    = Rinc\Increment::half();    // new Rinc\Increment(1/2)