package com.cnc;
public class Main {
public static void main(String[] args) {
//FLOAT
float myMinFloatVal = Float.MIN_VALUE;
float myMaxFloatVal = Float.MAX_VALUE;
System.out.println("FLOAT MINIMUM VALUE =" + myMinFloatVal);
System.out.println("FLOAT MAXIMUM VALUE =" + myMaxFloatVal);
//DOUBLE
System.out.println("");
double myMinDoubleVal = Double.MIN_VALUE;
double myMaxDoubleVal = Double.MAX_VALUE;
System.out.println("double MINIMUM VALUE =" + myMinDoubleVal);
System.out.println("");
System.out.println("double MAXIMUM VALUE =" + myMaxDoubleVal);
int i = 5;
float f = (float)5.77;
float f1 = 5.77f;
double d = 5.7755d;
double d1 = 5.7755;
int i2 = 5;
float f2 = 5f;
double d2 = 5d;
System.out.println("int is "+ i2+" "+"float is "+ f2+" "+"double is "+ d2);
int i3 = 5/3;
float f3 = 5f/3f;
double d3 = 5d/3d;//is more accurate & is faster than float
System.out.println("int is "+ i3+" "+"float is "+ f3+" "+"double is "+ d3);
//CHALLENGE
//CONVERT A GIVEN NUMBER OF POUNDS TO KILOGRAMS.
double numberOfPounds = 200d;
double conertedKilograms= numberOfPounds*0.45359237d;
System.out.println("Converted Kilograms = "+ conertedKilograms);
//BOTH CASES RESULTS ARE SAME
double pi = 3.1415927d;
double pi1= 3.1_415_927d;
System.out.println(pi);
System.out.println(pi1);
}
}
Both float and double are not great way to use where precise calculation are required.
Java has a class called as BigDecimal.
FLOAT MINIMUM VALUE =1.4E-45
FLOAT MAXIMUM VALUE =3.4028235E38
double MINIMUM VALUE =4.9E-324
double MAXIMUM VALUE =1.7976931348623157E308
int is 5 float is 5.0 double is 5.0
int is 1 float is 1.6666666 double is 1.6666666666666667
Converted Kilograms = 90.718474
3.1415927
3.1415927