round « float « Java Data Type Q&A

1. Floating point rounding (in java)

What is the best way of determining if a given float(or double) has no significant decimal places.

f(234.0)  = true
f(34.45)  = false
f(3.1322) = false
i.e. equivalent of EQ(((int)number) * 1.0 , ...

2. Java Unexpected Rounding of Double/Float

Can anyone explain the following behavior? This method is supposed to scale the loaded picture so that it is as large as it can be within certain bounds without going over.

private ...

4. The trouble with rounding floating point numbers

I read Trouble with rounding floating point numbers. In the comments section, a couple of people are complaining about "newer, fadish languages like java" that don't have decimal types. The article supplies some C code that highlights floating point precision errors and I tried those with floats in Java. Seems like you can't add 1/3f and 2/3f and get 1. I ...

5. Rounding a float value

If you really added 0.1f to 1.1f and got 0.2000001f, then your program or (highly unlikely) the Java runtime has a bug. I'm presuming that you mean that you got 1.2000001f. In that case, you are just seeing that floating-point arithmetic is not exact. You can't rely on the accuracy of the last digit. In some complex calculations, the inaccuracy extends ...

6. Rounding of float value

7. floating point round to 2.

8. Float Rounding Solution

10. Float to 3 s.f with no rounding

11. Rounding floats without utility class