Math examples
Math Excel examples, explained clearly.
Open a focused example to see the implementation path, copy-ready PHP, expected workbook behavior, and the production boundary that matters.
4examples in this category
21supported categories
5implementation paths
Monolithic library
Math examples with copy-ready, production-minded PHP.
Each example identifies the exact methods it uses and can be opened independently from the right-side index.
- 4
- examples
- 2
- documented methods
MnbExcel::formula()decimalColumns()<?php
declare(strict_types=1);
/*
Summary:
Round a number to a chosen number of decimal places.
Implementation note:
Number formatting changes display only; ROUND changes the calculated value.
*/
use Mnb\PHPExcel\MnbExcel;
$rows = [[
'Raw amount' => 1299.4567,
'Rounded' => MnbExcel::formula('ROUND(A2,2)', 1299.46),
]];
MnbExcel::fromArray($rows)
->withHeader()
->decimalColumns(['Raw amount', 'Rounded'], 2)
->save('round.xlsx');MnbExcel::formula()<?php
declare(strict_types=1);
/*
Summary:
Force rounding away from or toward zero.
Implementation note:
These functions are useful for billing units, package quantities, and conservative estimates.
*/
use Mnb\PHPExcel\MnbExcel;
$rows = [[
'Value' => 12.341,
'Round up' => MnbExcel::formula('ROUNDUP(A2,2)', 12.35),
'Round down' => MnbExcel::formula('ROUNDDOWN(A2,2)', 12.34),
]];
MnbExcel::fromArray($rows)
->withHeader()
->save('round-directions.xlsx');MnbExcel::formula()<?php
declare(strict_types=1);
/*
Summary:
Return the remainder after division.
Implementation note:
MOD is commonly used for alternating row rules, cycle allocation, and batch grouping.
*/
use Mnb\PHPExcel\MnbExcel;
$rows = [[
'Sequence' => 17,
'Group size' => 5,
'Remainder' => MnbExcel::formula('MOD(A2,B2)', 2),
]];
MnbExcel::fromArray($rows)
->withHeader()
->save('mod.xlsx');MnbExcel::formula()<?php
declare(strict_types=1);
/*
Summary:
Return the magnitude of a value without its sign.
Implementation note:
Keep the original signed value when direction still matters to the report.
*/
use Mnb\PHPExcel\MnbExcel;
$rows = [[
'Variance' => -245.50,
'Absolute variance' => MnbExcel::formula('ABS(A2)', 245.50),
]];
MnbExcel::fromArray($rows)
->withHeader()
->currencyColumns(['Variance', 'Absolute variance'], '$')
->save('abs.xlsx');No matching example found.Try a method name, task, or result.
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue