# Float vs. Double- Comparing both

To have high-precision calculations, it is preferred to use floating points to obtain high accuracy during computation. In many programming languages, floating points or real numbers are represented by two primitive data types i.e. float and double.

Both of these data types are used to assign and store real values in programming.

They both return decimal values but the precision and accuracy level is the main game changer between them. Besides these similarities, they both have various significant differences. Some of these major differences are explained in this article.

## Explanation of Float and Double with Example

To explain the difference between the results of float and double for the same problem, let us take an example in C++. We take two variables a and b having float and double data types respectively. Then we initialize both with the same value to divide 36.4656 by 5.8695. Let’s see the difference between their results.

```float a;
double b;
a = 36.4656/5.8695;
b = 36.4656/5.8695;
count << a;
count >> b;

/* output
6.212727 and 6.2127268080756
*/```

The results for float and double were 6.212727 and 6.2127268080756 respectively. So, you can see that the float yields the result up to 6 significant figures and then rounds off the answer while double yields the answer up to 13 significant figures and is a more accurate calculation of our given problem.

### Should I use Float or Double?

The choice is solely up to you but if you need more accuracy and precision without having any issues of storage space then use double. But if your system is short on memory then go for the float.

### Can we compare float and double in C++ ?

Yes, you can compare both of them in C++ but keep the precision factor in mind while doing so as two values can be accurate up to a certain precision level but can be different at different levels of precision.

### Why is Float used in C?

Float is lightweight and fast in speed as compared to double, which is why it is used in C and it is better to use Float instead of double in C to get things done more quickly and accurately.

### Is double slower than float?

Yes. Generally speaking, double is slower than float as it requires more memory bandwidth but is more precise than float.

## Final words

During the analysis of float vs double, the basic and most important difference we read is the accuracy and precision difference between both.

Concluding the article, I hope that you have come across all the differences between the float and double data types. Considering these differences you can easily choose where you should use your required data types. It all depends on the requirement and need of your program’s result.

Kindly give your precious reviews about the article.