Cast a float or double to an integral value : Data Type cast « Data Type « Java






Cast a float or double to an integral value

Cast a float or double to an integral value
    
//: c03:CastingNumbers.java
// What happens when you cast a float or double to an integral value?
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.

public class CastingNumbers {

  public static void main(String[] args) {

    double above = 0.7, below = 0.4;
    
    System.out.println("above: " + above);

    System.out.println("below: " + below);

    System.out.println("(int)above: " + (int)above);

    System.out.println("(int)below: " + (int)below);

    System.out.println("(char)('a' + above): " +  (char)('a' + above));

    System.out.println("(char)('a' + below): " +  (char)('a' + below));
  }
} ///:~



           
         
    
    
    
  








Related examples in the same category

1.A simple casting demo
2.Casting Demo
3.Get the minimum and maximum value of a primitive data types?
4.Class with methods for type conversion
5.Data type conversion
6.Data type Conversion Util
7.Convert Byte array to Int
8.Convert Number To Target Class
9.Convert byte array to Long
10.Convert long to Bytes
11.Conversion utilities
12.Get Time From Date
13.Get String From Date
14.A method used to build a date for use Marker XML and KML data
15.A method used to build a date for display in line with existing formatting rules