I want to convert exponential to decimal. e.g. 1.234E3
to 1234
.
9 Answers
It is not really a conversion, but about how you display the number. You can use NumberFormat to specify how the number should be displayed.
Check the difference:
double number = 100550000.75;
NumberFormat formatter = new DecimalFormat("#0.00");
System.out.println(number);
System.out.println(formatter.format(number));

- 9,421
- 8
- 37
- 50
-
can u tell me how to do the same for numbers that have decimal point. e.g. 1234567812.1212. The exponential notation will be 1.2345678121212E9. I need to bring it back to 1234567812.1212. If there are 4 numbers after decimal point , I need to get 4. If 5 number,then 5. – sai Dec 02 '09 at 09:01
-
Sai, use #.########. You can add more # after the decimal separator to increase the precision. But note that the maximum precision will be determined by the data type that you use. If you use double, for example, you will not get more than 17 decimal places (just check what happens if you print 1/3 without a formatter). So, if you include more than seventeen # after the decimal separator, it won't increase the precision. If you need more precision than double, see the BigDecimal class. – b.roth Dec 02 '09 at 09:35
How about BigDecimal.valueOf(doubleToFormat).toPlainString()

- 4,270
- 8
- 45
- 94

- 621
- 6
- 17
-
What would be the difference if I used toString() instead of toPlainString()? – Shiladittya Chakraborty Feb 04 '16 at 08:06
-
1@ShiladittyaChakraborty, the first sentence in the [API for BigDecimal.toString()](https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html#toString--) states that scientific notation will be used if an exponent is needed. – Paul Mar 08 '16 at 17:47
While working with Doubles and Long numbers in Java you will see that most of the value are displayed in Exponential form.
For Example: In following we are multiplying 2.35 with 10000 and the result is printed.
//Division example
Double a = 2.85d / 10000;
System.out.println("1. " + a.doubleValue());
//Multiplication example
a = 2.85d * 100000000;
System.out.println("2. " + a.doubleValue());
Result:
- 2.85E-4
- 2.85E8
Thus you can see the result is printed in exponential format. Now you may want to display the result in pure decimal format like: 0.000285 or 285000000. You can do this simply by using class java.math.BigDecimal
. In following example we are using BigDecimal.valueOf()
to convert the Double value to BigDecimal
and than .toPlainString()
to convert it into plain decimal string.
import java.math.BigDecimal;
//..
//..
//Division example
Double a = 2.85d / 10000;
System.out.println("1. " + BigDecimal.valueOf(a).toPlainString());
//Multiplication example
a = 2.85d * 100000000;
System.out.println("2. " + BigDecimal.valueOf(a).toPlainString());
Result:
- 0.000285
- 285000000
The only disadvantage of the above method is that it generates long strings of number. You may want to restrict the value and round off the number to 5 or 6 decimal point. For this you can use java.text.DecimalFormat
class. In following example we are rounding off the number to 4 decimal point and printing the output.
import java.text.DecimalFormat;
//..
//..
Double a = 2.85d / 10000;
DecimalFormat formatter = new DecimalFormat("0.0000");
System.out.println(formatter .format(a));
Result:
0.0003
I have just tried to compress this code with one line, it will print value of 'a' with two decimal places:
new DecimalFormat("0.00").format(BigDecimal.valueOf(a).toPlainString());
Happy Converting :)

- 60,504
- 58
- 273
- 437
the answer by @b.roth is correct only if it is country specific. I used that method and got i18n issue , because the new DecimalFormat("#0.00)
takes the decimal seperator of the particular country. For ex if a country uses decimal seperation as "," , then the formatted value will be in 0,00 ( ex.. 1.2e2 will be 120.00 in some places and 120,00 ) in some places due to i18n issue as said here..
the method that i prefer is `(new BigDecimal("1.2e2").toPlainString() )
just add following tag to jspx:-
<f:convertNumber maxFractionDigits="4" minFractionDigits="2" groupingUsed="false"/>

- 69,918
- 32
- 186
- 246

- 11
try the following
long l;
double d; //It holds the double value.such as 1.234E3
l=Double.valueOf(time_d).longValue();
you get the decimal value in the variable l.

- 4,258
- 9
- 45
- 80
You can do:
BigDecimal
.valueOf(value)
.setScale(decimalLimit, RoundingMode.HALF_UP)
.toPlainString()

- 30,334
- 10
- 78
- 137

- 1
- 1