Logo

Programming-Idioms

History of Idiom 79 > diff from v26 to v27

Edit summary for version 27 by VermilionWizard:
[C] Enhance explanation to include cases where explicit cast is necessary.

Version 26

2017-05-27, 19:58:31

Version 27

2018-03-02, 17:00:40

Idiom #79 Convert integer to floating point number

Declare floating point number y and initialize it with the value of integer x .

Idiom #79 Convert integer to floating point number

Declare floating point number y and initialize it with the value of integer x .

Code
float y = (float)x;
Code
float y = (float)x;
Comments bubble
The (float) isn't really necessary. The compiler will cast x automatically.
Comments bubble
The (float) isn't really necessary, unless x is a double or decimal type. The compiler will cast x automatically.