Logo

Programming-Idioms

History of Idiom 79 > diff from v4 to v5

Edit summary for version 5 by :

Version 4

2015-09-01, 21:32:22

Version 5

2015-09-02, 22:47:26

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 .

Imports
import std.conv : to;
Code
int x;
float y = to!float(x);
// or
float y = cast(float) x;
Comments bubble
the to function is safe and handles overflows while casting is faster and is unsafe.