PHP Math and Calendar Functions Reference
Read range, precision and domain rules before choosing a numeric helper. A convenient function does not select your rounding or accounting policy.
How it works
Integer division, floating-point division and rounding answer different questions. Randomness used for secret tokens must come from suitable cryptographic APIs. Calendar-conversion helpers operate under specific calendar conventions, while a loan deadline normally benefits from an explicit DateTimeImmutable/timezone policy. Some calendar APIs require the calendar extension; avoid assuming every PHP deployment includes it.
Run it locally
Run this complete source locally with PHP 8.2 or newer. Save it using the filename shown and run the command below. PHP is not currently available in Bhylu’s browser playground. Apache and MySQL are not needed for an ordinary CLI example.
php -l ref-numbers.php
php ref-numbers.phpDownload this source as a local PHP lab file. Keep lab files separate from the Bhylu project and production data.
Example
<?php
declare(strict_types=1);
echo intdiv(17,5), " full groups\n";
echo 17 % 5, " left\n";
echo number_format(12.5,2,".",""), " displayed\n";
Expected result
3 full groups
2 left
12.50 displayedDivision and remainder describe the whole grouping, while number_format produces presentation text. That formatted string is not the stored numeric source for later calculations. Negative amounts, locale display and rounding ties need separate tests when the application supports them.
Contracts to check
| API or term | Important boundary |
|---|---|
| intdiv, fmod, abs, min, max | Choose integer/remainder/domain behaviour explicitly. |
| round, ceil, floor, number_format | Distinguish rounding rules from display formatting. |
| random_int, random_bytes | Use appropriate unpredictability for security-sensitive choices. |
| cal_days_in_month, cal_to_jd, cal_from_jd | Calendar-extension operations need a stated calendar and valid date. |
| sqrt, log, pow, is_finite, is_nan | Check numeric domains and non-finite results. |
Related API names
This alphabetic inventory helps locate related calls. Availability was checked in the review runtime; it is not a recommendation to use every API or a claim that every overload/function was executed. Read the official entry for version, extension, failure and security details.
| Name | Review-runtime status |
|---|---|
abs() | Available in the PHP review runtime |
acos() | Available in the PHP review runtime |
acosh() | Available in the PHP review runtime |
asin() | Available in the PHP review runtime |
asinh() | Available in the PHP review runtime |
atan() | Available in the PHP review runtime |
atan2() | Available in the PHP review runtime |
atanh() | Available in the PHP review runtime |
base_convert() | Available in the PHP review runtime |
bindec() | Available in the PHP review runtime |
cal_days_in_month() | Available in the PHP review runtime |
cal_from_jd() | Available in the PHP review runtime |
cal_info() | Available in the PHP review runtime |
cal_to_jd() | Available in the PHP review runtime |
ceil() | Available in the PHP review runtime |
cos() | Available in the PHP review runtime |
cosh() | Available in the PHP review runtime |
decbin() | Available in the PHP review runtime |
dechex() | Available in the PHP review runtime |
decoct() | Available in the PHP review runtime |
deg2rad() | Available in the PHP review runtime |
easter_date() | Available in the PHP review runtime |
easter_days() | Available in the PHP review runtime |
exp() | Available in the PHP review runtime |
expm1() | Available in the PHP review runtime |
floor() | Available in the PHP review runtime |
fmod() | Available in the PHP review runtime |
frenchtojd() | Available in the PHP review runtime |
getrandmax() | Available in the PHP review runtime |
gregoriantojd() | Available in the PHP review runtime |
hexdec() | Available in the PHP review runtime |
hypot() | Available in the PHP review runtime |
intdiv() | Available in the PHP review runtime |
is_finite() | Available in the PHP review runtime |
is_infinite() | Available in the PHP review runtime |
is_nan() | Available in the PHP review runtime |
jddayofweek() | Available in the PHP review runtime |
jdmonthname() | Available in the PHP review runtime |
jdtofrench() | Available in the PHP review runtime |
jdtogregorian() | Available in the PHP review runtime |
jdtojewish() | Available in the PHP review runtime |
jdtojulian() | Available in the PHP review runtime |
jdtounix() | Available in the PHP review runtime |
jewishtojd() | Available in the PHP review runtime |
juliantojd() | Available in the PHP review runtime |
lcg_value() | Available in the PHP review runtime |
log() | Available in the PHP review runtime |
log10() | Available in the PHP review runtime |
log1p() | Available in the PHP review runtime |
max() | Available in the PHP review runtime |
min() | Available in the PHP review runtime |
mt_getrandmax() | Available in the PHP review runtime |
mt_rand() | Available in the PHP review runtime |
mt_srand() | Available in the PHP review runtime |
octdec() | Available in the PHP review runtime |
pi() | Available in the PHP review runtime |
pow() | Available in the PHP review runtime |
rad2deg() | Available in the PHP review runtime |
rand() | Available in the PHP review runtime |
round() | Available in the PHP review runtime |
sin() | Available in the PHP review runtime |
sinh() | Available in the PHP review runtime |
sqrt() | Available in the PHP review runtime |
srand() | Available in the PHP review runtime |
tan() | Available in the PHP review runtime |
tanh() | Available in the PHP review runtime |
unixtojd() | Available in the PHP review runtime |
Check the official PHP manual for detailed version and API contracts.