[Solution] warning C4305: ‘initializing’ : truncation from ‘double’ to ‘float’

VC++ Compiler throws warning C4305: ‘initializing’ : truncation from ‘double’ to ‘float’ warning when we try to declare float variable as double.

Remember

float M_PI = 3.1428571428571428     // This is actually double variable

will throw the warning: warning C4305: ‘initializing’ : truncation from ‘double’ to ‘float’

The right way to do declare float varible is

float M_PI = 3.1428571428571428f       //Right way to declare float variable

We only added a f at the end of the value.

This is our solution to the above problem :: warning C4305: ‘initializing’ : truncation from ‘double’ to ‘const float’

Samundra Shrestha

I work as fullstack developer. Having spent more than 5 years in the web development technologies, I aspire to create an environment where we can share, learn and grow together.

Leave a Reply

Your email address will not be published. Required fields are marked *