Hướng dẫn how do you make a value positive in php? - làm thế nào để bạn tạo một giá trị dương trong php?

❮ 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:

echo(abs(6.7) . "
");
echo(abs(-6.7) . "
");
echo(abs(-3) . "
");
echo(abs(3));
?>

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ố

Tham sốSự mô tả
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ị trở lại:Giá trị tuyệt đối của số
Loại trở lại:Float / Integer
Phiên bản PHP: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.4
    
    1 không còn chấp nhận các đối tượng nội bộ hỗ trợ chuyển đổi số.
  • Ví dụ
  • 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.4
    
    1 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:

    php

    ________số 8

    ?>      

    Output:

    6.4

    Tham khảo: http://php.net/manual/en/function.abs.php http://php.net/manual/en/function.abs.php


    (Php 4, Php 5, Php 7, Php 8)

    abs - giá trị tuyệt đốiAbsolute 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.4
    
    1

    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).float, the return type is also float, otherwise it is int (as float usually has a bigger value range than int).

    Thay đổi

    Phiên bảnSự mô tả
    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.4
    
    5

    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.4
    
    6

    Input : abs(6)
    Output : 6
    
    Input : abs(-6)
    Output : 6
    
    Input : abs(6.4)
    Output : 6.4
    
    Input : abs(-6.4)
    Output : 6.4
    
    7

    Input : abs(6)
    Output : 6
    
    Input : abs(-6)
    Output : 6
    
    Input : abs(6.4)
    Output : 6.4
    
    Input : abs(-6.4)
    Output : 6.4
    
    8