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
21focused categories
5implementation paths
01ROUNDRound a number to a chosen number of decimal places.
EasyExcel formula+
Round a number to a chosen number of decimal places.
MnbExcel::formula()decimalColumns()<?php
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');02ROUNDUP / ROUNDDOWNForce rounding away from or toward zero.
EasyExcel formula+
Force rounding away from or toward zero.
MnbExcel::formula()<?php
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');03MODReturn the remainder after division.
MediumExcel formula+
Return the remainder after division.
MnbExcel::formula()<?php
use Mnb\PHPExcel\MnbExcel;
$rows = [[
'Sequence' => 17,
'Group size' => 5,
'Remainder' => MnbExcel::formula('MOD(A2,B2)', 2),
]];
MnbExcel::fromArray($rows)
->withHeader()
->save('mod.xlsx');04ABSReturn the magnitude of a value without its sign.
EasyExcel formula+
Return the magnitude of a value without its sign.
MnbExcel::formula()<?php
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');Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue