user3369680
user3369680

Reputation:

What is a floating point array?

I am new to Java and my book refers to a floating point array. We have covered float and double. I understand that a float is less precise than a double.

However, the book has a problem where you display the largest and smallest values of a floating point array. I assumed you would use the following:

 float [] array = new float [100];

However, the book uses the following:

 double [] array = new double [100];

Maybe I am getting confused as this could be a play on words in my own mind. Can someone please advise if both of these examples would be a floating point array? I have searched Google as well as many forums, but I am still inconclusive.

Upvotes: 0

Views: 7177

Answers (3)

shashwat12
shashwat12

Reputation: 168

In java the numeric data type can be classified into to groups Integral Data Type and Floating point data types. The integral data type represents whole numbers. For integral data types we majorly use int. For using decimal numbers like 3.468468 or 0.516 we use floating point data types. Float and Double are both floating point data types. The only difference is that double is more precise than float and therefore takes more memory as well. In java double is the Default floating point data type. So if not specified all the floating point numbers will be double. Since the double has more precision so it may be the reason why the book has used the double array. Hope this helps.

Upvotes: 1

iamsuman
iamsuman

Reputation: 1413

A float is a Java data type which can store floating point numbers (i.e., numbers that can have a fractional part). Only 4 bytes are used to store float numbers giving a value range of -3.4028235E+38 to 3.4028235E+38

The double data type is a double-precision 64-bit IEEE 754 floating point. Its range of values is 4.94065645841246544e-324d to 1.79769313486231570e+308d (positive or negative). For decimal values, this data type is generally the default choice. As mentioned above, this data type should never be used for precise values, such as currency but you can use float.

Upvotes: 0

Dileep
Dileep

Reputation: 5440

Double and float are of almost similar only difference is in its precision points .

Float has about 7 decimal point precision where as a double has around 15 decimal point precision.

It does not make any difference, whether its used with an array or a variable.

Upvotes: 0

Related Questions