Hướng dẫn how do you round down in php? - làm thế nào để bạn làm tròn xuống trong php?
❮ Tham khảo toán học PHP Show
Thí dụSố tròn: echo(round(0.60) . " Hãy tự mình thử » Định nghĩa và cách sử dụngHàm vòng () làm tròn một số điểm nổi. Mẹo: Để làm tròn một số lên đến số nguyên gần nhất, hãy nhìn vào hàm cle (). To round a number UP to the nearest integer, look at the ceil() function. Mẹo: Để làm tròn một số xuống số nguyên gần nhất, hãy nhìn vào chức năng Sàn (). To round a number DOWN to the nearest integer, look at the floor() function. Cú phápvòng (số, độ chính xác, chế độ); Giá trị tham số
Chi tiết kỹ thuật
Nhiều ví dụ hơnThí dụSố tròn đến hai số thập phân: echo(round(4.96754,2) . " Hãy tự mình thử » Thí dụĐịnh nghĩa và cách sử dụng Hàm vòng () làm tròn một số điểm nổi. Mẹo: Để làm tròn một số lên đến số nguyên gần nhất, hãy nhìn vào hàm cle (). Mẹo: Để làm tròn một số xuống số nguyên gần nhất, hãy nhìn vào chức năng Sàn (). Cú pháp Hãy tự mình thử » ❮ Tham khảo toán học PHP 4 năm trước Esion99 tại gmail dot com — Rounds a float Greghenle tại Gmail Dot Com ¶Christian tại Deligant Dot Net(int|float 11 năm trướcMichaeldnelson dot mdn tại gmail dot com ¶13 năm trước Martinr tại Maarja Dot Net14 năm trước PHP tại silisoftware dot com ¶ 20 năm trước Goreyshi tại Gmail Dot Com ¶Dastra ¶
Trả về giá trị Giá trị được làm tròn vào Thay đổi
Ví dụVí dụ: Vòng 1 vòng () Ví dụround() examples Using PHP_ROUND_HALF_UP with 1 decimal digit precision float(1.6) float(-1.6) Using PHP_ROUND_HALF_DOWN with 1 decimal digit precision float(1.5) float(-1.5) Using PHP_ROUND_HALF_EVEN with 1 decimal digit precision float(1.6) float(-1.6) Using PHP_ROUND_HALF_ODD with 1 decimal digit precision float(1.5) float(-1.5)1 Ví dụ trên sẽ xuất ra: float(3) float(4) float(4) float(4) float(5.05) float(5.06) float(300) float(0) float(700) float(1000) Ví dụ #2 Làm thế nào Using PHP_ROUND_HALF_UP with 1 decimal digit precision float(1.6) float(-1.6) Using PHP_ROUND_HALF_DOWN with 1 decimal digit precision float(1.5) float(-1.5) Using PHP_ROUND_HALF_EVEN with 1 decimal digit precision float(1.6) float(-1.6) Using PHP_ROUND_HALF_ODD with 1 decimal digit precision float(1.5) float(-1.5)3 Ví dụ trên sẽ xuất ra: float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0) Ví dụ #2 Làm thế nào Using PHP_ROUND_HALF_UP with 1 decimal digit precision float(1.6) float(-1.6) Using PHP_ROUND_HALF_DOWN with 1 decimal digit precision float(1.5) float(-1.5) Using PHP_ROUND_HALF_EVEN with 1 decimal digit precision float(1.6) float(-1.6) Using PHP_ROUND_HALF_ODD with 1 decimal digit precision float(1.5) float(-1.5)5 Using PHP_ROUND_HALF_UP with 1 decimal digit precision float(1.6) float(-1.6) Using PHP_ROUND_HALF_DOWN with 1 decimal digit precision float(1.5) float(-1.5) Using PHP_ROUND_HALF_EVEN with 1 decimal digit precision float(1.6) float(-1.6) Using PHP_ROUND_HALF_ODD with 1 decimal digit precision float(1.5) float(-1.5)6 Using PHP_ROUND_HALF_UP with 1 decimal digit precision float(1.6) float(-1.6) Using PHP_ROUND_HALF_DOWN with 1 decimal digit precision float(1.5) float(-1.5) Using PHP_ROUND_HALF_EVEN with 1 decimal digit precision float(1.6) float(-1.6) Using PHP_ROUND_HALF_ODD with 1 decimal digit precision float(1.5) float(-1.5)7 Ví dụ trên sẽ xuất ra: Rounding modes with 9.5 float(10) float(9) float(10) float(9) Rounding modes with 8.5 float(9) float(8) float(8) float(9) Ví dụ #2 Làm thế nào
Using PHP_ROUND_HALF_UP with 1 decimal digit precision float(1.6) float(-1.6) Using PHP_ROUND_HALF_DOWN with 1 decimal digit precision float(1.5) float(-1.5) Using PHP_ROUND_HALF_EVEN with 1 decimal digit precision float(1.6) float(-1.6) Using PHP_ROUND_HALF_ODD with 1 decimal digit precision float(1.5) float(-1.5)6 $num 2Ví dụ trên sẽ xuất ra: Using PHP_ROUND_HALF_UP with 1 decimal digit precision float(1.6) float(-1.6) Using PHP_ROUND_HALF_DOWN with 1 decimal digit precision float(1.5) float(-1.5) Using PHP_ROUND_HALF_EVEN with 1 decimal digit precision float(1.6) float(-1.6) Using PHP_ROUND_HALF_ODD with 1 decimal digit precision float(1.5) float(-1.5) Ví dụ #2 Làm thế nào precision ảnh hưởng đến một chiếc phao
trần () - Phân số tròn lên ¶ Sàn () - Phân số tròn xuống
$num 8number_format () - Định dạng một số với hàng ngàn nhóm ¶ TakeSides tại Gmail Dot Com ¶
$precision 18 năm trước ¶ Sàn () - Phân số tròn xuống
$precision 1number_format () - Định dạng một số với hàng ngàn nhóm ¶ Sàn () - Phân số tròn xuống
$precision 1number_format () - Định dạng một số với hàng ngàn nhóm ¶ Sàn () - Phân số tròn xuống
$precision 1number_format () - Định dạng một số với hàng ngàn nhóm ¶ TakeSides tại Gmail Dot Com ¶
DePaula tại Unilogica dot com ¶ 5 năm trước
slimusgm tại gmail dot com ¶ Sàn () - Phân số tròn xuống
$precision 1number_format () - Định dạng một số với hàng ngàn nhóm ¶ TakeSides tại Gmail Dot Com ¶
number_format () - Định dạng một số với hàng ngàn nhóm ¶ TakeSides tại Gmail Dot Com ¶
$precision 18 năm trước ¶ DePaula tại Unilogica dot com
$precision 15 năm trước ¶ Sàn () - Phân số tròn xuống
$precision 1number_format () - Định dạng một số với hàng ngàn nhóm ¶ TakeSides tại Gmail Dot Com ¶
$precision 18 năm trước ¶ DePaula tại Unilogica dot com
$precision 15 năm trước ¶ slimusgm tại gmail dot com
precision 9serg tại kalachev dot ru ¶ ¶ djcox99 tại googlemail dot com ¶ float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)00 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)01 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)02 $precision 1Ẩn danh ¶ ¶
float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)04 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)05 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)06 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)07 $precision 1Jongbumi tại Gmail Dot Com ¶ ¶ DePaula tại Unilogica dot com float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)09 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)10 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)11 $precision 15 năm trước ¶ slimusgm tại gmail dot com float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)13 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)14 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)15 $precision 1serg tại kalachev dot ru ¶ ¶ TakeSides tại Gmail Dot Com ¶ float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)17 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)18 $precision 18 năm trước ¶ DePaula tại Unilogica dot com
float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)20 5 năm trước ¶ DePaula tại Unilogica dot com float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)21 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)22 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)23 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)24 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)25 $precision 15 năm trước ¶ slimusgm tại gmail dot com float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)27 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)28 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)29 $precision 1serg tại kalachev dot ru ¶ ¶ djcox99 tại googlemail dot com ¶ float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)31 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)32 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)33 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)34 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)35 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)36 $precision 1
number_format () - Định dạng một số với hàng ngàn nhóm ¶ TakeSides tại Gmail Dot Com ¶ float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)38 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)39 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)40 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)41 8 năm trước ¶ Sàn () - Phân số tròn xuống float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)42 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)43 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)44 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)45 $precision 1number_format () - Định dạng một số với hàng ngàn nhóm ¶ TakeSides tại Gmail Dot Com ¶
float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)47 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)48 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)49 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)50 $precision 1number_format () - Định dạng một số với hàng ngàn nhóm ¶ TakeSides tại Gmail Dot Com ¶ float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)52 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)53 $precision 18 năm trước ¶ TakeSides tại Gmail Dot Com ¶ float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)55 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)56 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)57 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)58 $precision 18 năm trước ¶ DePaula tại Unilogica dot com
float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)60 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)61 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)62 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)63 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)64 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)65 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)66 $precision 15 năm trước ¶ slimusgm tại gmail dot com float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)68 float(135.79) float(135.79) float(135.8) float(136) float(140) float(100) float(0)69 $precision 1Làm thế nào để tôi làm tròn đến 2 số thập phân trong PHP?Ví dụ số 1 vòng () Ví dụ Php Echo Round (3.4);// 3 Echo Round (3.5);// 4 Echo Round (3.6);// 4 vòng lặp (3.6, 0);// 4 vòng Echo (1.95583, 2);// 1,96 vòng Echo (1241757, -3);// 1242000 Echo Round (5.045, 2);// 5,05 Vòng Echo (5.055, 2);// 5.06?>round() examples
php echo round(3.4); // 3 echo round(3.5); // 4 echo round(3.6); // 4 echo round(3.6, 0); // 4 echo round(1.95583, 2); // 1.96 echo round(1241757, -3); // 1242000 echo round(5.045, 2); // 5.05 echo round(5.055, 2); // 5.06 ?>
Làm thế nào để bạn làm tròn phân chia trong PHP?Sử dụng hàm vòng () để có được giá trị tròn số nguyên.@Byscripts -8/3 = -3 chỉ là một cách hợp lệ để phân chia số nguyên hoạt động như -8/3 = -2.. @ByScripts -8/3 = -3 is just as valid a way for integer division to work as -8/3 = -2.
Làm thế nào để bạn làm tròn một số đến 10 gần nhất trong PHP?vòng () sẽ đi đến gần nhất theo mặc định.Chia cho 10, thực hiện trần, sau đó nhân với 10 để giảm các chữ số quan trọng.$ number = trần ($ input / 10) * 10;EDIT: Tôi đã làm điều đó theo cách này rất lâu .. nhưng câu trả lời của cao độ cao hơn.Divide by 10, do the ceil, then multiply by 10 to reduce the significant digits. $number = ceil($input / 10) * 10; Edit: I've been doing it this way for so long.. but TallGreenTree's answer is cleaner.
Vòng PHP là gì?Hàm vòng () trong PHP được sử dụng để làm tròn số điểm nổi.Nó có thể được sử dụng để xác định một giá trị chính xác cụ thể làm tròn số theo giá trị chính xác đó.Độ chính xác cũng có thể là âm hoặc bằng không.used to round a floating-point number. It can be used to define a specific precision value which rounds number according to that precision value. Precision can be also negative or zero. |