Logo

Programming-Idioms

  • C++
  • Clojure
  • Java

Idiom #79 Convert integer to floating point number

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

Float y = Float.parseFloat(String.valueOf(x));
import java.math.BigDecimal;
float y = new BigDecimal(x).floatValue();
float y = x;
int x = 10
float y = (float)x;
System.out.println(y);
float y = static_cast<float>(x);
(def y (float x))
Y : constant Float := Float (X);

New implementation...