← LOG/C/C++/ENTRY N° 46

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

FILED
READ
1 MIN
CATEGORY
C/C++
TAGS
[SOLVED] · HOW TO · VC++

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’

■ END OF ENTRY 46