PHP putaran () function
contoh
Floating-point pembulatan:
<?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));
?>
echo(round(0.60) . "<br>");
echo(round(0.50) . "<br>");
echo(round(0.49) . "<br>");
echo(round(-4.40) . "<br>");
echo(round(-4.60));
?>
Menjalankan contoh »
Definisi dan Penggunaan
round () fungsi dari titik pembulatan mengambang.
Tip: Untuk dibulatkan ke bilangan bulat terdekat, lihat ceil () fungsi.
Tip: Untuk dibulatkan ke bilangan bulat terdekat, lihat lantai () fungsi.
tatabahasa
round( number,precision,mode );
参数 | 描述 |
---|---|
number | 必需。规定要舍入的值。 |
precision | 可选。规定小数点后的尾数。默认是 0。 |
mode | 可选。规定表示舍入模式的常量:
|
rincian teknis
Pengembalian: | Setelah pembulatan nilai. |
---|---|
kembali jenis: | mengapung |
Versi PHP: | 4+ |
PHP Perbarui Log: | PHP 5.3: Ditambahkan parameter modus. |
contoh yang lebih
contoh 1
Angka dibulatkan ke dua desimal:
<?php
echo(round(4.96754,2) . "<br>");
echo(round(7.045,2) . "<br>");
echo(round(7.055,2));
?>
echo(round(4.96754,2) . "<br>");
echo(round(7.045,2) . "<br>");
echo(round(7.055,2));
?>
Menjalankan contoh »
contoh 2
konstan menggunakan nomor bulat:
<?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));
?>
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));
?>
Menjalankan contoh »
PHP Math Referensi