Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Java oddity

Author: Arturo Ochoa

Date: 07:50:18 09/09/02

Go up one level in this thread


On September 09, 2002 at 10:04:12, Ed Panek wrote:

>long x;
>double y;
>
>y = 2.01;
>x = (long)(y * 1000);
>
>
>guess what x equals? ...
>
>No, not 2010, but 2009 !!!!!!!!!!!!!!!
>
>Ed

Hello:

For operations with precision, I use the primitive float instead double when you
operate between different types.

	float y = (float) 2.01;
	long x;

	x = (long) (y * 1000);

	//////////////////////////////////

	y = (float) 2.00001;

	x = (long) (y * 100000);

	//////////////////////////////////


Here, you get the expected result.

Regards, Arturo.



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.