math « float « Java Data Type Q&A

1. Why is there a difference between the same value stored as a float and a double in Java?

I expected the following code to produce: "Both are equal", but I got "Both are NOT equal":

float a=1.3f;
double b=1.3;
 System.out.println("Both are equal");
 System.out.println("Both are NOT equal");
What is the reason for this? ...

2. Can 12.1 be represented exactly as a floating point number?

This is in reference to the comments in this question:

This code in Java produces 12.100000000000001 and this is using 64-bit doubles which can present 12.1 exactly. – Pyrolistical ...

3. ArithematicException in Java

In Java, (Number/0) throws an ArithematicException while (Number/0.0) = Infinity. Why is it so.?

4. How to round a float to the nearest quarter

Sometimes I need to round a float to the nearest quarter and sometimes to the nearest half. For the half I use

I can use Math.round(myFloat*4)/4f. but is there ...

5. Why do floats seem to add incorrectly in Java?

Possible Duplicates:
Is JavaScript's Math broken?
Java floating point arithmetic
I have the current code
for(double j = .01; j <= .17; j+=.01){

6. How to get byte[] from float number

How to get byte[] from float number? I need to create message where for data I have four bytes, datum can be unsigned int( it is easy to get byte[] from ...

7. why isnt there a Math.floor(float)?

Why is there only Math.floor(double)? I have a float and I want to round it "down".
do I have to cast it to double?