• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2118
  • 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
0
dravidnsk
Asked:
dravidnsk
1 Solution
 
ChristoferDutzCommented:
How about doing a little string reformating and using the direct method?

double d = 1.23e+4;

double d = Double.parseDouble("1.23e+4");
0
 
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 !!!
0
 
ChristoferDutzCommented:
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

0
 
rrzCommented:
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

0
 
KuldeepchaturvediCommented:
Or you can use NumberFormat object to format the numbers to your desired format.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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