The Difference Between "Floor" and "Truncate"

A non-integer exists between two integers; one greater, and one lesser. To convert such a number to an integer, one of these bounding integers is chosen as the new value. The choice depends on the function used. There are four common functions that remove the fractional part of a number to make it an integer.

  1. Round
  2. Ceiling
  3. Floor
  4. Truncate
Round picks the nearest integer, or if the distance is equal, then the greater integer. In other words, if the fractional part is < 0.5, then use the lower integer. If the fractional part is >= 0.5, then use the greater integer. (One common variation rounds to the nearest even number if it's 0.5.)

Ceiling always picks the greater integer.

Floor always picks the lower integer.

Truncate simply chops off the fractional part. In other words, it writes out the number in positional notation and stops at the decimal point, using that integer as the new value.

Although Floor and Truncate seem identical, and often give identical results, there is a slight difference. For values above zero, and all integers, they are identical. However, for all negative non-integers x,

truncate(x) = floor(x) + 1 = ceiling(x)

This occurs because truncation does not involve the sign of a number, but the floor calculation does. For example, the first integer lower than 0.1 is 0, but the first integer lower than -0.1 is -1.
Therefore:

floor(0.1) = 0
truncate(0.1) = 0
floor(-0.1) = -1
truncate(-0.1) = 0

For all x >= 0,

truncate(x) = floor(x)

For all x <= 0,

truncate(x) = ceiling(x)