Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • D

Idiom #79 Convert integer to floating point number

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

import std.conv : to;
int x;
float y = to!float(x);
// or
float y = cast(float) x;

the to function is safe and handles overflows while casting is faster and is unsafe.
Y : constant Float := Float (X);

New implementation...