I am trying to read the values from excel sheet using java. When i type more than 10 letters in a cell in excel it is displaying in exponential form like "9.78313E+2". but this is not the real number what i given. Can any body help me out in this. How can i convert the above exponential form to original number using java language.
Thanks in advance
You can convert as follows, for example:
new BigDecimal("406770000244E+12").toBigInteger();
Double.parseDouble("9.78313E+2");
gives me
978.313
For more info see the doc.
Following your further queries below, if you've entered 4256411411
and Excel is presenting this as 4.26E+09
, putting that value into parseDouble()
will only give you 4260000000
. If you want the original, perhaps you need to output the Excel file in a fuller format for your Java program, and/or query it using a Java/Excel API (e.g. POI)
Sorry, but none of the answers above Double.parseDouble()
and Double.valueOf()
... solved my problem, and I continued to get the exponential 'E' value...
This link has a much better approach for the problem, and as I've written there - there is a very good solution:
I needed to convert some double to currency values, and fount that most to the solution are OK but not for me.
The DecimalFormat
was eventually the way for me, so here is what I've done:
public String foo(double value) //Got here 6.743240136E7 or something..
{
DecimalFormat formatter;
if(value - (int)value > 0.0)
formatter = new DecimalFormat("0.00"); //Here you can also deal with rounding if you wish..
else
formatter = new DecimalFormat("0");
return formatter.format(value);
}
As you can see, if the number is natural I get - say - 20000000 instead of 2E7 (etc) - without any decimal point.
and if it's decimal, I get only 2 decimal digits.
Hope this will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With