Why use integers if doubles can do more?

So I was wondering, why do we use integers if doubles can store more numbers? just a simple question

maybe to save space, or for stuff that can only be whole numbers, like an index (for an array or an ArrayList)

1 Like

It is all about:

memory usage

Integers require less memory than doubles.

Integer operations are generally faster than floating-point operations which consequently leads to faster code build and execution.

At the end of the day depends on the task and entity you are trying to build. If you are building an application that requires mathematical accuracy and calculations then doubles are what you need, if not then integers may be what you need.

1 Like