Feeds:
Posts
Comments

Archive for September, 2011

Hi;

It’s been too long time to wrote article. Whatever …

I try to increased float data type in loop at php and java. But it didn’t give me a true result at last 2 or 3 step.

for example try this at java;

		for (float i=0f; i<=1f; i+=0.1){
			System.out.println(i);
		}

You’ll see this

0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.70000005
0.8000001
0.9000001

The solution is;

		for (int count = 0; count <= 10; count += 1) {
			float x = count / 10.0f;
			System.out.println(x);
		}

This shows you the true results;

0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0

See you on other articles…

Advertisements

Read Full Post »