• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2352
  • Last Modified:

how to convert from exponential(E) to ordinary float.

Hi ,

I have a problem to  convert from exponential(E) to ordinary float.
the exponential value are retrive from database and save as bean that will add in list that go to jsp  page .

example : 1234.56E2  to 123456.00
1 Solution
How about doing a little string reformating and using the direct method?

double d = 1.23e+4;

double d = Double.parseDouble("1.23e+4");
dravidnskAuthor Commented:
The value i have retrive from the database is 1.25E6 like that it  comes i want to set this to some bean ,that bean is added List, that List i used in jsp page for dispaly (Tag lib using)

I dont know where i want to change the value into float (the bean variable datatype is float )
and also i dont know how to change that !!!
Well then try this code:

public class Test {
	public static void main(String args[]) {
		String convertedStr = "1234.56E2";
		if(convertedStr.indexOf("E") != -1) {
		    convertedStr = convertedStr.substring(0,  convertedStr.indexOf("E") + 1) + "+" + convertedStr.substring(convertedStr.indexOf("E") + 1, convertedStr.length());
		float fl = Float.parseFloat(convertedStr);

Open in new window

Try this demo JSP.
<%@ page import="java.math.BigDecimal" %>
   String input1 = "1234.56E2";
   BigDecimal bd1 = new BigDecimal(input1);
   String output1 = bd1.setScale(2).toPlainString();
   float f1 = bd1.floatValue();
   String input2 = "1.25E6";
   BigDecimal bd2 = new BigDecimal(input2);
   String output2 = bd2.setScale(2).toPlainString();
   float f2 = bd2.floatValue();
<%="output1 is " + output1 + " and f1 is " + f1%><br/>
<%="output2 is " + output2 + " and f2 is " + f2%>

Open in new window

Or you can use NumberFormat object to format the numbers to your desired format.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now