❮ Tham khảo toán học PHP
Thí dụ
Trả về giá trị tuyệt đối của các số khác nhau:
Hãy tự mình thử »
Định nghĩa và cách sử dụng
Hàm abs [] trả về giá trị tuyệt đối [dương] của một số.
Cú pháp
Giá trị tham số
con số | Yêu cầu. Chỉ định một số. Nếu số là loại float, loại trả về cũng nổi, nếu không thì đó là số nguyên |
Chi tiết kỹ thuật
Giá trị tuyệt đối của số |
Float / Integer |
4+ |
❮ Tham khảo toán học PHP
Thay đổi
Phiên bản
Input : abs[6] Output : 6 Input : abs[-6] Output : 6 Input : abs[6.4] Output : 6.4 Input : abs[-6.4] Output : 6.41 không còn chấp nhận các đối tượng nội bộ hỗ trợ chuyển đổi số.
Thay đổi
Phiên bản
Input : abs[6] Output : 6 Input : abs[-6] Output : 6 Input : abs[6.4] Output : 6.4 Input : abs[-6.4] Output : 6.41 không còn chấp nhận các đối tượng nội bộ hỗ trợ chuyển đổi số.abs[] function is an inbuilt function in PHP which is used to return the absolute [positive] value of a number. The abs[] function in PHP is identical to what we call modulus in mathematics. The modulus or absolute value of a negative number is positive.
Syntax:
number abs[ value ]
Ví dụ The abs[] function accepts single parameter value which holds the number whose absolute value you want to find.
Ví dụ #1 abs [] ví dụ It returns the absolute value of the number passed to it as argument.
Examples:
Input : abs[6] Output : 6 Input : abs[-6] Output : 6 Input : abs[6.4] Output : 6.4 Input : abs[-6.4] Output : 6.4
Ví dụ trên sẽ xuất ra:
EEP2004 tại UKR DOT Net When a positive number is passed as a parameter:
Output:
6
1 năm trước When a negative number is passed as a parameter:
Output:
6
Chương trình 3: Khi một số dương với các vị trí thập phân được truyền dưới dạng tham số: When a positive number with decimal places is passed as a parameter:
Output:
6.4
Chương trình 4: Khi một số âm với các vị trí thập phân được truyền dưới dạng tham số: When a negative number with decimal places is passed as a parameter:
Output:
6.4
Tham khảo: //php.net/manual/en/function.abs.php //php.net/manual/en/function.abs.php
[Php 4, Php 5, Php 7, Php 8]
abs - giá trị tuyệt đối — Absolute value
Sự mô tả
abs [int | float ____1010]: int | float[int|float Input : abs[6]
Output : 6
Input : abs[-6]
Output : 6
Input : abs[6.4]
Output : 6.4
Input : abs[-6.4]
Output : 6.4
0]: int|float
Thông số
Input : abs[6] Output : 6 Input : abs[-6] Output : 6 Input : abs[6.4] Output : 6.4 Input : abs[-6.4] Output : 6.41
Giá trị số để xử lý
Trả về giá trị
Giá trị tuyệt đối của
Input : abs[6] Output : 6 Input : abs[-6] Output : 6 Input : abs[6.4] Output : 6.4 Input : abs[-6.4] Output : 6.41. Nếu đối số
Input : abs[6] Output : 6 Input : abs[-6] Output : 6 Input : abs[6.4] Output : 6.4 Input : abs[-6.4] Output : 6.41 thuộc loại float, loại trả về cũng nổi, nếu không thì đó là int [vì float thường có phạm vi giá trị lớn hơn int].float, the return type is also float, otherwise it is int [as float usually has a bigger value range than int].
Thay đổi
8.0.0 | abs [int | float ____1010]: int | float |
Thông số
Input : abs[6]
Output : 6
Input : abs[-6]
Output : 6
Input : abs[6.4]
Output : 6.4
Input : abs[-6.4]
Output : 6.4
1abs[] example
Input : abs[6] Output : 6 Input : abs[-6] Output : 6 Input : abs[6.4] Output : 6.4 Input : abs[-6.4] Output : 6.45
Giá trị số để xử lý
Trả về giá trị ¶
Giá trị tuyệt đối của Input : abs[6]
Output : 6
Input : abs[-6]
Output : 6
Input : abs[6.4]
Output : 6.4
Input : abs[-6.4]
Output : 6.4
1. Nếu đối số Input : abs[6]
Output : 6
Input : abs[-6]
Output : 6
Input : abs[6.4]
Output : 6.4
Input : abs[-6.4]
Output : 6.4
1 thuộc loại float, loại trả về cũng nổi, nếu không thì đó là int [vì float thường có phạm vi giá trị lớn hơn int].
Input : abs[6] Output : 6 Input : abs[-6] Output : 6 Input : abs[6.4] Output : 6.4 Input : abs[-6.4] Output : 6.46
Input : abs[6] Output : 6 Input : abs[-6] Output : 6 Input : abs[6.4] Output : 6.4 Input : abs[-6.4] Output : 6.47
Input : abs[6] Output : 6 Input : abs[-6] Output : 6 Input : abs[6.4] Output : 6.4 Input : abs[-6.4] Output : 6.48