# Float vs Double

By | August 18, 2019 In programming languages like C, C++, and Java we have two data types to represent floating points number. In simple words, floating points are those numbers which contain decimal points such as 5.000, 6.2123, etc. Both the real number and decimal number considered under floating points numbers.

In C++ and Java, we have two in-built data types float and double to represent all floating points, but there is always a confusion which data type to choose as both are supposed to do the same work. Though in small scale programming there is no such difference seen in the use of float or double, when we are talking about data science or scientific computing even a single point can have a huge impact, there a programmer should have the complete knowledge of which data type should he use.

Here in this article, we have provided some head to head comparison between float and double data type and also mentioned when to choose which data type.

Before comparing both the data types lets have a look at what is float and double?

## Float

Float is a Single-precision floating-point format data type which is basically used to represent floating points number.

Float usually occupy 32 bits in computer memory with 4 bytes.

If we compare it to Integer data types, an integer can have a maximum value of 2,147,483,647, whereas a float can have a maximum value of 3.4028235 × 1038.

A float can provide 6 digits after the decimal point.

## Double

Double is an IEEE 754 64 bits Double-precision floating-point format data type which is also used to represent Floating points number.

IEEE 754 is a standard representation of floating points number in Computer. A double can occupy 12 bytes of space in computer memory and store 15 to 16 numbers after the decimal point.

As compare to float data type double show more preciseness and occupy more memory. The preciseness signifies the accuracy of the result.

 Double Float Explanation Double-precision floating-point, use to represent floating points number Single-precision floating-point, use to represent floating points number Memory 64-bits 32 bits Size 8 bytes 4 bytes Precisions More precision Less precision Digits after decimal points A double can have 15 to 16 digits after decimal points A float can have 6 digits after decimal point Maximum Value or Range Double has more range than float 3.4028235 × 1038 Advantages It is more precise than float Mostly all programming language have float data types Manly libraries support it

### When to use Float:

We generally use a float with a low scale program where point accuracy does not matter that much. As it has less size and occupies can work with 32 bits memory it is very fast. If you want to make a program with and want to keep its size as minimum as possible then you should use float data type for floating points number.

### Where to use double?

When you are writing code for high-end computers where RAM shortage and battery drainage are not such an issue there you should use double data type.

Double provides more range and precision as compared to float so where point accuracy matter a lot there we should use double data types.