PHP round() Funksie
Voorbeeld
Ronde getalle:
<?php
echo(round(0.60) . "<br>");
echo(round(0.50) . "<br>");
echo(round(0.49) . "<br>");
echo(round(-4.40) . "<br>");
echo(round(-4.60));
?>
Definisie en gebruik
Die round()-funksie rond 'n drywende-puntgetal af.
Wenk: Om 'n getal OP na die naaste heelgetal af te rond, kyk na die ceil()- funksie.
Wenk: Om 'n getal AF te rond tot die naaste heelgetal, kyk na die floor()- funksie.
Sintaksis
round(number,precision,mode);
Parameterwaardes
Parameter | Description |
---|---|
number | Required. Specifies the value to round |
precision | Optional. Specifies the number of decimal digits to round to. Default is 0 |
mode | Optional. Specifies a constant to specify the rounding mode:
|
Tegniese besonderhede
Terugkeerwaarde: | Die afgeronde waarde |
---|---|
Retourtipe: | Vlot |
PHP weergawe: | 4+ |
PHP Changelog: | PHP 5.3: Die modusparameter is bygevoeg |
Meer voorbeelde
Voorbeeld
Rond getalle af tot twee desimale:
<?php
echo(round(4.96754,2) . "<br>");
echo(round(7.045,2) . "<br>");
echo(round(7.055,2));
?>
Voorbeeld
Rond getalle af deur die konstantes te gebruik:
<?php
echo(round(1.5,0,PHP_ROUND_HALF_UP) . "<br>");
echo(round(-1.5,0,PHP_ROUND_HALF_UP) . "<br>");
echo(round(1.5,0,PHP_ROUND_HALF_DOWN) . "<br>");
echo(round(-1.5,0,PHP_ROUND_HALF_DOWN) . "<br>");
echo(round(1.5,0,PHP_ROUND_HALF_EVEN) . "<br>");
echo(round(-1.5,0,PHP_ROUND_HALF_EVEN) . "<br>");
echo(round(1.5,0,PHP_ROUND_HALF_ODD) . "<br>");
echo(round(-1.5,0,PHP_ROUND_HALF_ODD));
?>
❮ PHP Wiskunde Verwysing