PHP Math16 Dec 2024 | 5 min read PHP provides many predefined math constants and functions that can be used to perform mathematical operations. PHP Math: abs() functionThe abs() function returns absolute value of given number. It returns an integer value but if you pass floating point value, it returns a float value. SyntaxExampleOutput: 7 7 7.2 PHP Math: ceil() functionThe ceil() function rounds fractions up. SyntaxExampleOutput: 4 8 -4 PHP Math: floor() functionThe floor() function rounds fractions down. SyntaxExampleOutput: 3 7 -5 PHP Math: sqrt() functionThe sqrt() function returns square root of given argument. SyntaxExampleOutput: 4 5 2.6457513110646 PHP Math: decbin() functionThe decbin() function converts decimal number into binary. It returns binary number as a string. SyntaxExampleOutput: 10 1010 10110 PHP Math: dechex() functionThe dechex() function converts decimal number into hexadecimal. It returns hexadecimal representation of given number as a string. SyntaxExampleOutput: 2 a 16 PHP Math: decoct() functionThe decoct() function converts decimal number into octal. It returns octal representation of given number as a string. SyntaxExampleOutput: 2 12 26 PHP Math: base_convert() functionThe base_convert() function allows you to convert any base number to any base number. For example, you can convert hexadecimal number to binary, hexadecimal to octal, binary to octal, octal to hexadecimal, binary to decimal etc. SyntaxExampleOutput: 1010 PHP Math: bindec() functionThe bindec() function converts binary number into decimal. SyntaxExampleOutput: 2 10 11 PHP Math FunctionsLet's see the list of important PHP math functions.
Next TopicPhp math log function |
We request you to subscribe our newsletter for upcoming updates.