Andrew
Andrew

Reputation: 6394

Java and decimals E numbers

Java comes up with numbers like 9.870699812169277E-4

How should I interpret it? Is there a way to parse it in Java and display without that E?

Upvotes: 6

Views: 11245

Answers (2)

user219882
user219882

Reputation: 15844

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

Related

Java: Format double with decimals and Format numbers in java

Upvotes: 11

Peter Lawrey
Peter Lawrey

Reputation: 533530

I don't know of any language which doesn't support this notation (except perhaps machine code) Even most calculators support it.

I suspect the languages you have used before support this notation, however it just wasn't used.

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

For your interest there is a P notation e.g. 0x1.fffffffffffffP+1023 which is a hex notation for a double.

Upvotes: 2

Related Questions