Skip to content
BENIBIX Learn

Integer vs Floating-Point Number

People think 3 and 3.0 are the same number to a computer, and they are not. An integer is a whole number, and its sums are exact. A floating-point number has a decimal part, and it keeps a very close value rather than an exact one. That is why 0.1 + 0.2 can give 0.30000000000000004. For money, count in whole cents with integers.

Development🧩 Programming Concepts

Integer

A whole number, like 7, 0 or -12, with nothing after the point.

An integer is a whole number with no part after the point. 7, 0 and -12 are integers, but 2.5 is not. Programs use integers for counting things, like items in a cart or the number of a page. Maths on integers is exact, so no tiny errors creep in. Most languages call the type int.

Example
A shop counts 3 books in a cart as the integer 3. Half a book cannot be bought, so a whole number fits.
Why it matters
Counts, positions and ids are integers. Using the right type keeps the sums exact.
Full entry
Development🧩 Programming Concepts

Floating-Point Number

A number with a decimal part, like 3.5. It can be off by a hair.

A floating-point number is a number with a decimal part, like 3.5. Computers store these in a fixed number of bits, so most of them are kept as a very close guess. That is why 0.1 + 0.2 can come out as 0.30000000000000004. The tiny error is fine for a game or a map. For money, programs use whole cents or a special decimal type instead.

Example
A fitness app stores a 5.2 km run as a float. For the price of the plan it uses 999 cents, not 9.99.
Why it matters
Distances, weights and scores often have decimals. Knowing the tiny error keeps you from using floats for money.
Full entry

In one line

Integer
A whole number, like 7, 0 or -12, with nothing after the point.
Floating-Point Number
A number with a decimal part, like 3.5. It can be off by a hair.