Julio Rosario Julio Rosario - 1 year ago 53
Java Question

Why does Eclipse doesn't display a number less than zero?

Every time I run this test program it display,

0.0 instead of 0.5

Does anyone know how to fix this in Eclipse?

public class Test {

public static void main(String[]args){

double distance;

distance = 1/2;



Answer Source

Your division is Integer division. There is no fault of Eclipse. Try following:

distance = 1/2.0;


distance = 1.0/2;