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

Posted on 2009-04-27
Last Modified: 2012-08-13
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
Question by:dravidnsk
    LVL 20

    Expert Comment

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

    double d = 1.23e+4;

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

    Author Comment

    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 !!!
    LVL 20

    Expert Comment

    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

    LVL 27

    Accepted Solution

    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

    LVL 19

    Expert Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    Suggested Solutions

    I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
    For Sennheiser, comfort, quality and security are high priority areas. This paper addresses the security of Bluetooth technology and the supplementary security that Sennheiser’s Contact Center and Office (CC&O) headsets provide.  
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now