View Single Post
  #2 (permalink)  
Old 07-31-2007, 11:28 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
If a number has a decimal it is a double. To make such a number a float you can do
Code:
float f = (float)3.14; // cast // or float c = 3.14f; // or 3.14F
And any number of lesser precision can be assigned to a reference of higher precision.
Code:
float f = 25; double d = 15f; long b = 88; // int
To see what java says:
Code:
class FloatTest { public static void main(String[] args) { check(-343); check(3.14); check(0x12345); check(42e7); check(2001.0D); check(2.81F); } private static void check(Number n) { System.out.println(n + " = " + n.getClass().getName()); } }
Reply With Quote