PHPackages                             filmtools/mround - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. filmtools/mround

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

filmtools/mround
================

Rounds a number to the nearest multiple of another number (mround, ceiling, floor)

1.2.1(8mo ago)117.5k↓10.5%2MITPHPPHP ^8.3

Since Jun 27Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/filmtools/mround)[ Packagist](https://packagist.org/packages/filmtools/mround)[ RSS](/packages/filmtools-mround/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (10)Used By (2)

FilmTools · mround
==================

[](#filmtools--mround)

**PHP implementation for Excel's mround function: Returns a number rounded to the nearest multiple of another number.**

[![Composer Version](https://camo.githubusercontent.com/798ccd8934eb1673a4899c3b1210cd92ba1cb2d38c8cd2d67f4f31f9cc908653/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f66696c6d746f6f6c732f6d726f756e64)](https://packagist.org/packages/filmtools/mround)[![PHP version](https://camo.githubusercontent.com/cba868fb386a9efc065eed50c522e078c7b3d724631dedb800c9ebcc39515047/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f66696c6d746f6f6c732f6d726f756e64)](https://packagist.org/packages/filmtools/mround)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/06d50d26a8bf4694416ae73ad366d255e6fbad408a5bede6f569e6b3ec0576f8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f66696c6d746f6f6c732f6d726f756e642f7068702e796d6c)](https://github.com/filmtools/mround/actions/workflows/php.yml)[![Packagist License](https://camo.githubusercontent.com/acdfe2b2c180af97d34a2bd626b5d48ba0d87004f4180bb857735dadcfc964e3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f66696c6d746f6f6c732f6d726f756e64)](LICENSE.txt)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/9b5313e914c18b06240a77770eab7adc2888cc280aa451608c08c1d3a2034cec/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f66696c6d746f6f6c732f6d726f756e642f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/filmtools/mround/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/75e0a927198668f842d264a1ab5544d3bf76b984a522a68c1dbabc6e0daf5d78/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f66696c6d746f6f6c732f6d726f756e642f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/filmtools/mround/?branch=master)

What's in this package?
-----------------------

[](#whats-in-this-package)

**Rounding to a nearest multiple or fraction**with the ***mround*** function, corresponding to MROUND

**Rounding *down* to a nearest multiple or fraction**with the ***mfloor*** function, corresponding to FLOOR

**Rounding *up* to a nearest multiple or fraction**with the ***mceil*** function, corresponding to CEILING

All these are bundled in a callable **MRounder** class; the rounding behaviour is defined by an optional contructor parameter.

Please see the desktop software documentation for [Excel](https://support.office.com/en-us/article/mround-function-c299c3b0-15a5-426d-aa4b-d2d5b3baf427), [LibreOffice](https://help.libreoffice.org/Calc/Mathematical_Functions#MROUND), or [OpenOffice](https://wiki.openoffice.org/wiki/Documentation/How_Tos/Calc:_MROUND_function) and the original PHP implementation by Nasser Hekmati on [StackOverflow.](https://stackoverflow.com/a/48643210/3143771)

Installation
------------

[](#installation)

```
$ composer require filmtools/mround
```

The functions
-------------

[](#the-functions)

The functions are namespaced, so you will have to mention it in your `use` statements:

```
use function FilmTools\MRounder\mround;
use function FilmTools\MRounder\mfloor;
use function FilmTools\MRounder\mceil;
```

The functions all round *num* to the nearest multiple of *base*; their signature is:

```
fn( float $num, float $base);

```

### mround · “normal” rounding

[](#mround--normal-rounding)

```
