Scientific notation in Java

Faizan Ahmad :
    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?

candied_orange :

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.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=116546&siteId=1
Recommended