Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the differences between intval and floor functions in php

Shulou Source: shulou.com Published: 2022-06-01 18:43:57 10月15日 Update

This article mainly talks about "what are the differences between intval and floor functions in php". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the differences between intval and floor functions in php?"

Differences: 1, the intval () function is directly rounded off the decimal part, while the floor () function when the parameter is greater than 1, the decimal part is rounded, when the parameter is less than 1, the decimal part is removed and 1 is added on the basis of the integer. 2. The intval () function can be converted to binary, but not the floor function.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

In php, both the intval and floor functions can be used for decimal rounding, so what's the difference between them? Let's take a look.

Floor () function

The floor () function rounds down to the nearest integer.

Syntax: floor (x)

Returns the next integer not greater than x, rounding off the fractional portion of x. The type returned by floor () is still float, because the range of float values is usually larger than integer.

Output:

0055-6-6

Intval () function

The intval () function is used to get the integer value of a variable.

Syntax:

Int intval (mixed var, int [base])

Return value: integer

Function type: PHP system function

Output:

forty-four

The intval () function returns the integer value of the variable var by using the specified binary base conversion (the default is decimal). Intval () cannot be used for object, otherwise an E_NOTICE error will be generated and 1 will be returned.

At this point, I believe you have a deeper understanding of "what is the difference between intval and floor functions in php". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Functions decimals integers parts content parameters variables values systems syntax binary learning output no practical deeper between interests functions decimal Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Microsoft Shulou Technology NVidia Linux