Skip to Content

Convert Java float Primitive Value to Float Object Example

  1. /*
  2.   Convert float to Float object Example
  3.   This example shows how a float primitive value can be converted to a Float object
  4. */
  5.  
  6. public class JavafloatToFloatExample {
  7.  
  8.   public static void main(String[] args) {
  9.     float f = 10.56f;
  10.    
  11.     /*
  12.     Use Float constructor to convert float primitive type to a Float object.
  13.     */
  14.    
  15.     Float fObj = new Float(f);
  16.     System.out.println(fObj);
  17.  
  18.   }
  19. }
  20.  
  21. /*
  22. Output of the program would be
  23. 10.56
  24. */