0

I was doing a simple calculation program in java when I encountered this problem. I want to convert centimeter square to meter square. 1 cm² = 0.0001 m². When i create the program in java to do this conversion I got result in '1.0E-4' instead of '0.0001'. I don't know why it is showing in that way. may someone guide me how to do it or something that may help

Here is the code:

import java.io.*;

class First {

    public static void main(String x[]) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            System.out.println("Please Enter the number");
            double number = Double.parseDouble(br.readLine());
            double d1 = 0.0001;
            double result = number * d1;
            System.out.println("Result is " + result);
        } catch(Exception ex) {
            ex.printStackTrace();
        }

    }

}
Unihedron
  • 10,902
  • 13
  • 62
  • 72
Sahil Manchanda
  • 9,812
  • 4
  • 39
  • 89
  • 2
    http://en.wikipedia.org/wiki/Scientific_notation – Smutje Aug 14 '14 at 09:30
  • 2
    possible duplicate of [How to print double value without scientific notation using Java?](http://stackoverflow.com/questions/16098046/how-to-print-double-value-without-scientific-notation-using-java) – Smutje Aug 14 '14 at 09:31
  • thanks for redirecting me to that question page. those three way works (DecimalFormat,string.format,BigDecimal). Sting.format is suited best in my case :) – Sahil Manchanda Aug 14 '14 at 09:40

1 Answers1

0

Doubles within a certain range are printed as a base and an exponent using the scientific notation. 1.0E-4 simply means 1 * 10^(-4), or 0.0001, so the answer you're getting is correct. As suggested by Smutje, you can change the way in which doubles are printed, like this.

Community
  • 1
  • 1
Malt
  • 28,965
  • 9
  • 65
  • 105