2
    System.out.println(Math.pow(10 , -10));

I wrote this line and output should be 10.0E-10 , right? But instead it shows 1.0E-10 . What might be the reason behind this?

3
  • how? would you care to explain? Commented Dec 9, 2018 at 18:03
  • 2
    1 * 10^-10 is what Java is giving you. Commented Dec 9, 2018 at 18:05
  • @FaizanAhmad Please consider accepting the answer that you think is the best. Commented Dec 10, 2018 at 14:10

2 Answers 2

4

The notation xey means x*10^y.

Math.pow(10 , -10) means 10 raised to the power -10, or 10^-10. This is equal to 1*10^-10, which expressed in the xey notation, is 1e-10.

Sign up to request clarification or add additional context in comments.

Comments

2

10.0E-10

means

10.0 x 10-10

But

Math.pow(10 , -10)

means

10-10

If you want a handy way to work with 10.0E-10 try

System.out.println(new BigDecimal("10.0E-10"));

Output: 1.00E-9

or

System.out.println(Double.valueOf("10.0E-10"));

Output: 1.0E-9

Which is best depends on which consideration is more important to you. Respectively: faithfully matching storage to presentation in base 10 or performance.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.