❮ Tham khảo toán học PHP
Thí dụ
Số tròn:
Hãy tự mình thử »
Đị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 []. 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áp
vòng [số, độ chính xác, chế độ];
Giá trị tham số
con số | Yêu cầu. Chỉ định giá trị thành vòng |
độ chính xác | Không bắt buộc. Chỉ định số chữ số thập phân để làm tròn đến. Mặc định là 0 |
cách thức | Không bắt buộc. Chỉ định một hằng số để chỉ định chế độ làm tròn:
|
Chi tiết kỹ thuật
Giá trị tròn |
Trôi nổi |
4+ |
Php 5.3: Tham số chế độ đã được thêm |
Nhiều ví dụ hơn
Thí dụ
Số tròn đến hai số thập phân:
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.
echo[round[1.5,0,PHP_ROUND_HALF_UP] . "
"];
echo[round[-1.5,0,PHP_ROUND_HALF_UP] . "
"];
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 [].
echo[round[-1.5,0,PHP_ROUND_HALF_DOWN] . "
"];
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 [].
echo[round[-1.5,0,PHP_ROUND_HALF_EVEN] . "
"];
Cú pháp
echo[round[-1.5,0,PHP_ROUND_HALF_ODD]];
?>
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 $num
, int $precision
= 0, int $mode
= PHP_ROUND_HALF_UP
]: float
11 năm trước
Michaeldnelson 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 ¶
PHP_ROUND_HALF_UP
| Vòng num cách xa số 0 khi nó ở một nửa ở đó, tạo ra 1,5 thành 2 và -1,5 thành -2. |
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]3 | Vòng num về phía 0 khi nó ở một nửa ở đó, biến 1,5 thành 1 và -1,5 thành -1. |
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]5 | Vòng num về phía giá trị thậm chí gần nhất khi nó ở đó một nửa, làm cho cả 1,5 và 2,5 thành 2. |
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]7 | Vòng num về phía giá trị lẻ gần nhất khi nó nằm ở đó một nửa, biến 1,5 thành 1 và 2,5 thành 3. |
Trả về giá trị
Giá trị được làm tròn vào precision
đã cho như một chiếc phao.float.
Thay đổi
8.0.0 | num không còn chấp nhận các đối tượng nội bộ hỗ trợ chuyển đổi số. |
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 precision
ảnh hưởng đến một chiếc phao
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 precision
ảnh hưởng đến một chiếc phao
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 precision
ảnh hưởng đến một chiếc phao
$num
0
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
- Ví dụ #3
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]
0 Ví dụ - Ví dụ #4
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]
0 vớiprecision
ví dụ - Xem thêm
trần [] - Phân số tròn lên ¶
Sàn [] - Phân số tròn xuống
$num
3
$num
4
$num
5
$num
6
$num
7
$num
8number_format [] - Định dạng một số với hàng ngàn nhóm ¶
TakeSides tại Gmail Dot Com ¶
$num
9
$precision
0
$precision
18 năm trước ¶
Sàn [] - Phân số tròn xuống
$precision
2
$precision
3
$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
5
$precision
6
$precision
7
$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
9
$mode
0
$mode
1
$mode
2
$mode
3
$mode
4
$precision
1number_format [] - Định dạng một số với hàng ngàn nhóm ¶
TakeSides tại Gmail Dot Com ¶
$mode
6
$mode
7
$mode
8
DePaula tại Unilogica dot com ¶
5 năm trước
PHP_ROUND_HALF_UP
0
slimusgm tại gmail dot com ¶
Sàn [] - Phân số tròn xuống
PHP_ROUND_HALF_UP
1
PHP_ROUND_HALF_UP
2
$precision
1number_format [] - Định dạng một số với hàng ngàn nhóm ¶
TakeSides tại Gmail Dot Com ¶
PHP_ROUND_HALF_UP
4
PHP_ROUND_HALF_UP
5
number_format [] - Định dạng một số với hàng ngàn nhóm ¶
TakeSides tại Gmail Dot Com ¶
PHP_ROUND_HALF_UP
7
PHP_ROUND_HALF_UP
8
$precision
18 năm trước ¶
DePaula tại Unilogica dot com
num
0
num
1
num
2
$precision
15 năm trước ¶
Sàn [] - Phân số tròn xuống
num
4
num
5
$precision
1number_format [] - Định dạng một số với hàng ngàn nhóm ¶
TakeSides tại Gmail Dot Com ¶
num
7
num
8
num
9
precision
0
precision
1
$precision
18 năm trước ¶
DePaula tại Unilogica dot com
precision
3
precision
4
$precision
15 năm trước ¶
slimusgm tại gmail dot com
precision
6
precision
7
precision
8
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 ¶ ¶
$precision
1
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
1