Number Types: Floating-point Types

  double f = 4.35;

  System.out.println(100 * f); // prints 434.99999999999994
Click here to see how to store 4.35 in a memory box

   double data type has 8 bytes = 64 bits

   4.35 = 100.01 0110 0110 0110 0110 0110 ...in binary

  double balance = 13.75;

  int dollars = balance; // Error

  int dollars = (int) balance; // OK

   Cast discards fractional part.

long rounded = Math.round(balance);
// if balance is 13.75, then rounded is set to 14

import java.util.Scanner;

public class RoundNumber
{
   public static void main(String[] args)
   {
     Scanner input = new Scanner(System.in);
     System.out.println("Enter a floating number");
     double x = input.nextDouble(); 
     
	double HundredTimes = x * 100;
        double y = Math.round(HundredTimes) / 100.0 ;

	System.out.println("Round "+x + " into two decimal places: " + y);
   }
}