Operators on Floating-Point Values in Java Programming

Operators on Floating-Point Values in Java Programming

Previous Home Next

 

The Java language supports two primitive floating point types: float and double, and their wrapper class counterparts, Float and Double.

The Java language supports two primitive floating point types: float and double, and their wrapper class counterparts, Float and Double. These are based on the IEEE 754 standard,which defines a binary standard for 32-bit floating point and 64-bit double precision floating point binary-decimal numbers

Float data type can hold value ranges from -3.402823 * 10^38 to 3.302823 * 10^38. It is known as single precision floating point numbers and takes 32 bits (four bytes) of memory.

Floating point numbers can be declared as given below.

float <identifier_name>;
Or
float <identifier_name> = <value>f;


Double data type in Java represents double precision value which is more accurate representation of floating point numbers as it allows more decimal places. A double values ranges from -1.79769313486232 * 10 ^ 308 to 1.79769313486232 * 10 ^ 308.

Double variable can be declared as given below.
double <identifier_name>;
Or
double <identifier_name> = <value>;
 
 double pi, r, A;

r = 10.8;

pi = 3.14;


 
class CircleArea {

Public static void main (String args[]) {

double pi, r, A;

r = 10.8;

pi = 3.14;

A= pi * r * r;

System.out.println(“Area of circle is “ + A”);
}

}


Previous Home Next