0

I know this is a pretty stupid question but I can't seem to understand why it isn't working. The code in java looks something like this:

public class Main {

public static void main(String[] args) {
    // TODO Auto-generated method stub


    double d=5/100;
    System.out.println(d);
}

}

However on the input instead of giving me 0.06 it gives me 0.05 it gives me 0.0.

Any ideas?

David Mathers
  • 163
  • 2
  • 7

1 Answers1

1

Try this

 public static void main(String[] args)
  {
     double d=5.0/100.0;
    System.out.println(d);

  }

You must use double variables to Java do not round results.

maarkeez
  • 98
  • 1
  • 3