NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - round

Trieda

Koreň \ Bez triedy

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ázovDátový typPredvolená hodnotaPopis
$valfloat

The value.

$precisionint 0

The accuracy of rounding. It can also be negative.

$modeint PHP_ROUND_HALF_UP

Specifies how the function should round the half of a number (tenths, hundredths, ...).

  • PHP_ROUND_HALF_UP - Rounds the half up (1.5 will be 2).
  • PHP_ROUND_HAL­F_DOWN - Rounds the half down (1.5 will be 1).
  • PHP_ROUND_HAL­F_EVEN - Rounds the half to the nearest even number (1.5 will be 2).
  • PHP_ROUND_HAL­F_ODD - Rounds the half to the nearest odd number (1.5 will be 1).

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
      Aktivity