Link to home
Start Free TrialLog in
Avatar of dravidnsk
dravidnskFlag for India

asked on

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
Avatar of ChristoferDutz
ChristoferDutz
Flag of Germany image

How about doing a little string reformating and using the direct method?

double d = 1.23e+4;

double d = Double.parseDouble("1.23e+4");
Avatar of dravidnsk

ASKER

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

ASKER CERTIFIED SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Or you can use NumberFormat object to format the numbers to your desired format.