Extract integer part of a number

2.5k Views Asked by At

I want to extract the integer part of number.

For example, I have the number 2.754 and the expected result would be 2.

Can i do it in a mathematical way?

2

There are 2 best solutions below

3
On BEST ANSWER

In a mathematical way is a pretty vague term.

Consider the tangent function $\tan(x)$ and the usual branch of its inverse, $\arctan(x)$, from $\mathbb R$ to $(-\pi/2,\pi/2)$.

Then with appropriate scalings and shiftings

$$f(x)=\frac1\pi\arctan\left(\tan\left(\pi\left(x+\frac12\right)\right)\right)+\frac12$$

is a sawtooth signal of period $1$, i.e. the fractional part of $x$.

enter image description here

Then $x-f(x)$ is the integer part.

This definition doesn't work for integers though :(

0
On

Yes, this is the floor function, $f(x)=\lfloor x\rfloor$. For a real number $a$, the integer part of $a$ is denoted $\lfloor a\rfloor$ (i.e. the floor of $a$).

Edit: Note that this notation is given as \lfloor x \rfloor, where \lfloor is the left side of the floor (i.e. \lfloor=$\lfloor$) and \rfloor is the right side of the floor (i.e. \rfloor=$\rfloor$).