Logo

Programming-Idioms

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

Idiom #79 Convert integer to floating point number

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

y = float(x)
Y : constant Float := Float (X);
float y = (float)x;
let y = float_of_int(x)
(def y (float x))
float y = static_cast<float>(x);
float y = x;
import std.conv : to;
int x;
float y = to!float(x);
// or
float y = cast(float) x;
double y = x.toDouble();
y = x / 1
real :: y
y = x
y := float64(x)
y = fromInteger x :: Double
let y = x + .0
int x = 10
float y = (float)x;
System.out.println(y);
Float y = Float.parseFloat(String.valueOf(x));
float y = x;
import java.math.BigDecimal;
float y = new BigDecimal(x).floatValue();
(defparameter *y* (float x))
y = x + .0
y = (16 ^ 13) + x - (16 ^ 13)
$y = (float) $x;
var
  y: single;
begin
  y := x;
end;
my $y = $x;
y = x.to_f
let y = x as f64;

New implementation...