PHP - round
Trieda
Metóda - round
(PHP 4, PHP 5, PHP 7)
The round() function returns a rounded number.
Procedurálne
- function round (float $val, int $precision = 0, int $mode = PHP_ROUND_HALF_UP) : float
Parametre
| Názov | Dátový typ | Predvolená hodnota | Popis |
|---|---|---|---|
| $val | float | The value. | |
| $precision | int | 0 | The accuracy of rounding. It can also be negative. |
| $mode | int | PHP_ROUND_HALF_UP | Specifies how the function should round the half of a number (tenths, hundredths, ...).
|
Mávratovej hodnoty
Vracia: float
The rounded number.
Príklady
<?php
echo round(5) . '<br />';
echo round(5.1) . '<br />';
echo round(5.4) . '<br />';
echo round(5.5) . '<br />';
echo round(5.8) . '<br />';
echo round(5483.47621, 2) . '<br />';
echo round(5483.47621, -2) . '<br />';
echo round("4,8") . "<br />"; // the compiler cuts it just to 4
echo round("4.8") . "<br />"; // the compiler is able to convert the data type
echo round(4, 8) . "<br />";
echo round(4.8) . "<br />";
echo round(4.5, 0, PHP_ROUND_HALF_DOWN) . "<br />";
echo round(4.5, 0, PHP_ROUND_HALF_UP) . "<br />";
Súvisiace manuály
- function ceil (float $value) : float
- function floor (float $value) : mixed
- function number_format (float $number, int $decimals = 0, string $dec_point = ., string $thousands_sep = ,) : string
