Search code examples
c++floating-pointliteralsautotype-deduction

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


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?


Solution

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

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