# float 2 « float « Java Data Type Q&A

### 4. Inaccuracy in float calculations?    forums.oracle.com

Hi I am making a small game and every 20ms I am doing some plusses and minuses on float values. However, I have a problem with my calculations not adding up. For instance I have a float x that every 20ms gets 0.2f added to it up to 4.0f max. However, it never reaches this value since its more like 3.80000000000007 ...

### 5. a simple question concerning float point    forums.oracle.com

float to double conversion: public static void main(String[] args) { float f1=1161.02F; double d1=f1; float f2=1148.08F; double d2=f2; double dtmp1=d2/d1; double d3=1162.02; double d4=1148.08; double dtmp2=d4/d3; } I thought dtmp1==dmp2, but they are different. dtmp1=0.9888545733416493 dtmp2=0.9888546278272553 furthermore, i found that d1!=1162.02 but 1161.02001953125 d2!=1148.03 but 1148.0799560546875 Can someone tell me why the result likes this? thanks. whether i put "strictfp" on ...

### 7. Floating points    forums.oracle.com

FP is unsuitable for use on currency quantities by virtue of not having any of the desired behaviour of a fixed-point decimal-based number system, which is what currencies are expressed in, and they are generally implemented using round-to-even. Reply #3 is the correct answer. The paper that is cited in this thread is the only reference or evidence required. If you ...

### 9. Floating point Collsion Detection    forums.oracle.com

I have an player that move around in a 2D map. The value of x and y are in floating points. Now i want it to collide with another player that move around too in the map. Both the player can rotate around too. I have tried many ways including rectangle drawing to detect collsion but its not accurate or very ...

### 13. Removing a Floating JToolBar    forums.oracle.com

Hello, I have noticed a little problem while working with JToolBars and I've been wondering if it should be considered a Bug or a "Feature"... When adding a JToolBar, it becomes possible to move it from one border to another using the BorderLayout LayoutManager. But there is one case where we can detach the JToolBar completely from its original container and ...

### 16. How to transmit a float - the best method ?    forums.oracle.com

Hi, I have the following problem: I must send a float through a TCP connection and I want to know what is the best method to do this. I use the java.nio package to put the float into a ByteBuffer. So we have 2 sockets (Client & Server) and we explored a few methods: 1 - Datagramm 2 - Datastream What's ...

### 17. Floating point differences between Java 1.5 and Java 6    forums.oracle.com

Hi all. One of our unit tests started failing on introduction of Java 6, and it turns out that the operations in question are floating point operations. We're performing some floating point math on pixel values for an image, and depending on the JRE version, a different result is generated. In addition to this, the floating point maths runs around 100 ...