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?
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.
11 Answers. Show activity on this post. Yes.
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.
Explanation: Given 3.14 is a double constant.
Type of literal 3.5
is double
. For float
please use 3.5f
You can play with this snippet to see various type information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With