Logo

Programming-Idioms

  • Obj-C
  • Java
  • Python

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)
int x = 10
float y = (float)x;
System.out.println(y);
import java.math.BigDecimal;
float y = new BigDecimal(x).floatValue();
float y = x;
Float y = Float.parseFloat(String.valueOf(x));
Y : constant Float := Float (X);

New implementation...