Monday, December 29, 2008

What are Floating Point Data Types in Java

Welcome back to Java Code Online. As I have promised in my previous article, that i will discuss all the data types in Java. So here I am back again, with the second data type in Java known as the Floating Point Data Types. Floating point data Types are useful when dealing with fractional values and are actually linked with the "real" numbers. This is unlike Integer Data Type in Java which are linked to "whole" numbers.

Floating Point Data Types in Java are of two types. they are:-
1. float (32 bits)
2. double (64 bits)

I will discuss both of these data types in detail below.

"float" data type takes 32 bits, and is single precision. Since the value of precision is lower then the "double" data type, the "float" data type occupy less memory as compared to the "double" data type. Moreover the processing of "float" is comparatively faster as compared to a "double" data type in Java.

The downside of using "float" is that, the precision is smaller then "double". So very small and very large values cannot be stored in a "float". Apart from that "float" meets all the requirements for a normal coder.

"double" consumes 64 bit of storage and is double precision. This data type is most used for scientific calculations, or places where very high degree of precision is required by the application.

I hope the article helped you understand about Floating Point Data Types in Java. If you liked this article then do leave a comment. For more info on Java keep buzzing Java Code Online.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.