❮ 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
Michaeldnelson dot mdn tại gmail dot com ¶
13 năm trước — Rounds a float
Martinr tại Maarja Dot Net
14 năm trước[int|float $num
, int $precision
= 0, int $mode
= PHP_ROUND_HALF_UP
]: float
PHP tại silisoftware dot com ¶
20 năm trướcGoreyshi tại Gmail Dot Com ¶
Dastra ¶10 năm trước
Feha tại Vision Dot đến ¶
Hayley Watson ¶
3 năm trướcomnibus tại omnibus dot edu dot pl ¶
PHP_ROUND_HALF_UP
| 14 năm trước |
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 | PHP tại silisoftware dot com ¶ |
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 | 20 năm trước |
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 | Goreyshi tại Gmail Dot Com ¶ |
Dastra ¶
10 năm trướcfloat.
Feha tại Vision Dot đến ¶
8.0.0 | 14 năm trước |
PHP tại silisoftware dot com ¶
20 năm trướcround[] 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
Goreyshi tại Gmail Dot Com ¶
float[3] float[4] float[4] float[4] float[5.05] float[5.06] float[300] float[0] float[700] float[1000]
Dastra ¶
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
Goreyshi tại Gmail Dot Com ¶
float[135.79] float[135.79] float[135.8] float[136] float[140] float[100] float[0]
Dastra ¶
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
Goreyshi tại Gmail Dot Com ¶
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]
Dastra ¶
$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
2Goreyshi tại Gmail Dot Com ¶
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]
Dastra ¶
- 10 năm trước
- Feha tại Vision Dot đến ¶
- Hayley Watson ¶
3 năm trước ¶
8 năm trước
$num
3
$num
4
$num
5
$num
6
$num
7
$num
8omnibus tại omnibus dot edu dot pl ¶ ¶
22 năm trước
$num
9
$precision
0
$precision
1slimusgm tại gmail dot com ¶
8 năm trước
$precision
2
$precision
3
$precision
1serg tại kalachev dot ru ¶ ¶
8 năm trước
$precision
5
$precision
6
$precision
7
$precision
1serg tại kalachev dot ru ¶ ¶
8 năm trước
$precision
9
$mode
0
$mode
1
$mode
2
$mode
3
$mode
4
$precision
1serg tại kalachev dot ru ¶ ¶
djcox99 tại googlemail dot com ¶
$mode
6
$mode
7
$mode
8
6 năm trước ¶
djcox99 tại googlemail dot com ¶
PHP_ROUND_HALF_UP
0
Ẩn danh ¶ ¶
8 năm trước
PHP_ROUND_HALF_UP
1
PHP_ROUND_HALF_UP
2
$precision
16 năm trước ¶
$precision
1
PHP_ROUND_HALF_UP
4
PHP_ROUND_HALF_UP
5
serg tại kalachev dot ru ¶ ¶
djcox99 tại googlemail dot com ¶
PHP_ROUND_HALF_UP
7
PHP_ROUND_HALF_UP
8
$precision
1Ẩn danh ¶ ¶
6 năm trước
num
0
num
1
num
2
$precision
1 $precision
1 ¶
8 năm trước
num
4
num
5
$precision
1Jongbumi tại Gmail Dot Com ¶ ¶
Thủ công tại CKDevelop Dot org ¶
num
7
num
8
num
9
precision
0
precision
1
$precision
1Twan tại Ecreation Dot NL ¶ ¶
22 năm trước
precision
3
precision
4
$precision
112 năm trước ¶
Mojo urk ¶
precision
6
precision
7
precision
8
precision
94 năm trước ¶
Esion99 tại gmail 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
1Greghenle tại Gmail Dot Com ¶ ¶
5 năm trước
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
1Christian tại Deligant Dot Net ¶
6 năm trước
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
1 $precision
1 ¶
Jongbumi 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
1Thủ công tại CKDevelop Dot org ¶ ¶
djcox99 tại googlemail 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
1Ẩn danh ¶ ¶
6 năm trước
float[135.79] float[135.79] float[135.8] float[136] float[140] float[100] float[0]20
$precision
1 ¶
djcox99 tại googlemail 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
1Ẩn danh ¶ ¶
6 năm trước
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
1 $precision
1 ¶
Jongbumi tại Gmail 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
serg tại kalachev dot ru ¶ ¶
Mojo urk ¶
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
4 năm trước ¶
8 năm trước
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
1Esion99 tại gmail dot com ¶
Greghenle 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
1serg tại kalachev dot ru ¶ ¶
Thủ công tại CKDevelop Dot org ¶
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
1Twan tại Ecreation Dot NL ¶ ¶
djcox99 tại googlemail 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
1Ẩn danh ¶ ¶
6 năm trước
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
1 $precision
1 ¶
Mojo urk ¶
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