Logo

Programming-Idioms

  • Elixir
  • 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 .

import java.math.BigDecimal;
float y = new BigDecimal(x).floatValue();
Float y = Float.parseFloat(String.valueOf(x));
float y = x;
int x = 10
float y = (float)x;
System.out.println(y);
y = x / 1

The / operator always returns a float.
Y : constant Float := Float (X);

New implementation...