Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does auto deduce this variable as double and not float? [duplicate]

In the snippet below, auto deduces the variable to double, but I want float.

auto one = 3.5;

Does it always use double for literals with a decimal point? How does it decide between float and double?

like image 253
Abhinav Kinagi Avatar asked Aug 16 '19 05:08

Abhinav Kinagi


People also ask

Why do we use double instead of float?

Double is more precise than float and can store 64 bits, double of the number of bits float can store. Double is more precise and for storing large numbers, we prefer double over float. For example, to store the annual salary of the CEO of a company, double will be a more accurate choice.

Can every float be represented as a double?

11 Answers. Show activity on this post. Yes.

Is float more efficient than double?

double has 2x more precision than float. float is a 32-bit IEEE 754 single precision Floating Point Number – 1 bit for the sign, 8 bits for the exponent, and 23* for the value.

Is 3.14 A double or float?

Explanation: Given 3.14 is a double constant.


1 Answers

Type of literal 3.5 is double. For float please use 3.5f

You can play with this snippet to see various type information.

like image 127
Gyapti Jain Avatar answered Sep 28 '22 07:09

Gyapti Jain