Home> Common Problem> body text

What is the basic function of int() function

藏色散人
Release: 2020-05-31 11:38:44
Original
17056 people have browsed it

What is the basic function of int() function

#What are the basic functions of the int() function?

INT() function is a type of VFP numerical function, which rounds a real number (which can be a mathematical expression) to be rounded down to the nearest integer. You can use the INT function to return a decimal integer, such as 4.323, which returns 4. It is not rounded, but rounded. Even if 4.987 is 4.987, it returns 4, not 5.

The INT function will return the integer value of the real number rounded down. Its syntax format is INT (number), where number is a real number that needs to be rounded. For example, the return value of INT(8.6) is 8, and the return value of INT(-8.6) is -9. The TRUNC function truncates the decimal part of a number and returns the integer part of the number.

Its syntax format isTRUNC (number, number_digits), where number is the number that needs to be truncated, number_digits is the number that specifies the rounding precision, and the default is 0. For example, the return value of function TRUNC(8.5) is 8, and the return value of TRUNC(-8.5) is -8.

Although these two functions are rounding functions, their algorithms are different. The INT function returns the integer that is smaller than the given parameter and is closest to the parameter, while the TRUNC function directly returns the integer minus the decimal part.

Function

The int() function is to convert a number or base type string into an integer. INT(x) can find the largest integer not larger than x.

Function

int(x=0)
Copy after login

int(x, base=10), the default value of base is 10, which means that when the value of base is not specified, the function will process x in decimal.

Syntax

The following is the syntax of the int() method:

class int(x, base=10)
Copy after login

Parameters

x —String or number.

base — base number, default decimal.

Return value

Return integer data.

Comments

In some other programming languages, this function is called the "rounding" function.

FIX and CINT functions also complete the rounding function

The above is the detailed content of What is the basic function of int() function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
int
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!