Floating-Point Types in java

By: aathishankaran Emailed: 1747 times Printed: 2434 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

Floating-Point Types in java


Floating-point numbers, also known as real numbers, are used when evaluating expressions that require fractional precision. For example, calculations such as square root, or transcendentals such as sine and cosine. Result in a value whose precision requires a floating-point type. Java implements the standard (IEEE-754) set of floating-point types and operators. There are two kinds of floating-point types, float and double, which represent single- and double-precision numbers, respectively. Their width and ranges are shown here:


            Name               width in Bits                  Range


            double                          64                    1.7e-308 to 1.7e+308

            float                              32                    3.4e-038 to 3.4e+038



            The type float specifies a single-precision value that uses 32 bits of storage. Single precision is faster on some processors and takes half as much space as double precision, but will become imprecise when the values are either very large or very small. Variables of type float are useful when you need a fractional component, but don’t require a large degree of precision. For example, float can be useful when representing dollars and cents.



            Double precision, as denoted by the double keyword, users 64 bits to store a value. Double precision is actually faster than single precision on some modern processors that have been optimized for high-speed mathematical calculations. All transcendental math functions, such as sin(), cos(), and sqrt(), return double values. When you need to maintain accuracy over many iterative calculations, or are manipulating large-valued numbers, double is the best choice.


            Here is a short program that uses double variables to compute the area of a circle:


//compute the area of a circle.

class Area {

     Public static void main (String args[]) {

          double pi, r, a;


          r = 10.8;

          pi = 3.1416;

          a= pi * r * r;


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



Java Home | All Java Tutorials | Latest Java Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.

Bookmark and Share


Be the first one to add a comment

Your name (required):

Your email(required, will not be shown to the public):

Your sites URL (optional):

Your comments:

More Tutorials by aathishankaran
Web Security Issues
The Web User's Perspective
Server-side plug-Ins
The best way to avoid security vulnerabilities with new server
JavaScript Security
Window Object
Working with Status Bar Messages
Retrieving a Portion of a String
Referencing Windows
Math Object
Frame Object
Document Object
Closing Windows
Built-in Object in Javascript
Textarea Object

More Tutorials in Java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Java File
Java String
Count number of vowels, consonants and digits in a String in Java
Reverse a number in Java
Student marks calculation program in Java
Handling Fractions in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program
MultiLevel Inheritance sample in Java
Multiple Inheritance sample in Java
Java program using Method Overriding
Java program to check if user input is an even number

More Latest News
Most Viewed Articles (in Java )
How to Send SMS using Java Program (full code sample included)
Using StringTokenizer in Java
Count number of vowels, consonants and digits in a String in Java
Method Overriding in Java
The Basic Structure of a Simple Java program
Vector example in Java
XML and Java - Parsing XML using Java Tutorial
Stack example in Java - push(), pop(), empty(), search()
Student marks calculation program in Java
append() in Java
wait(), notify() and notifyAll() in Java - A tutorial
Recursion in java
FileReader and FileWriter example program in Java
InetAddress Example program in Java
Use of try and catch in Java
Most Emailed Articles (in Java)
Update contents of a file within a jar file
Java Chat Client Sample Applet
Execute system commands in a Java Program
J2EE Services
Insert, Delete, Search, Print an int Array in Java
Get user input in Java
instanceof operator example in Java
Reading from a file and writing to a file using Java program
static keyword in Java
ThreadGroup Sample in Java
String Concatenation using Java
Sample Java Script that displays a movable clock
Multiple Inheritance sample in Java
Convert numbers to word as per Indian number system in java
Step by Step guide to setup freetts for Java