Java and decimal numbers E numbers

Hello and Merry Christmas everyone.

I tried to do this and also looked at StackOverflow, but I could not figure out how to interpret this.

Java is a little different from other languages ​​I have worked with before. It comes with numbers like 9.870699812169277E-4

How do I interpret this? Is there any way to parse it in Java and display E without it?

Thank you very much.

+4
source share
2 answers

You can use NumberFormat.

Code

 // you can format to any output you want NumberFormat formatter = new DecimalFormat("0.00000000000"); String string = formatter.format(9.870699812169277E-4); System.out.println(string); 

Result

 0.00098706998 

Additional examples at http://www.exampledepot.com/egs/java.text/FormatNumExp.html

Similar

Java: double format with decimals and Format numbers in java

+10
source

I do not know a single language that does not support this notation (except, possibly, machine code). Even most calculators support it.

I suspect that the languages ​​you used before supporting this notation, however, it just was not used.

9.870699812169277E-4 - the same 9.870699812169277 * 10-4 or 0.0009870699812169277

For your interest there is a notation P, for example. 0x1.fffffffffffffP+1023 , which is the hexadecimal notation for double.

+1
source

Source: https://habr.com/ru/post/1388061/


All Articles