1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Tallinn, .ee
    Rep Power

    Question Plz help, problems with arithmetic...

    Hi there.
    I have a form where customers input numbers(both types like 123 and 123.54), and i need to pass this numbers to .jsp file and do some arithmetic operations with it.
    So i have form.
    here is piece of form's code:

    <form name="form1" method="get" action="update.jsp">

    <input type="text" name="price" size="30">

    <input type="submit" name="submit" value="Submit">



    Next here is the piece of jsp file code:
    //getting the parameter

    String fprice = request.getParameter("price");

    //converting parameter to double type

    Double x = Double.valueOf(fprice)

    // now i want to do some arithmetic

    double y = x / 1.18;

    And i have error here:
    org.apache.jasper.JasperException: Unable to compile C:\tomcat\work\DEFAULT\ROOT\ladu\update_12.java:96: Incompatible type for /. Can't convert java.lang.Double to double.
    double y = x / 1.18;

    Could any1 help me plz?
    best regards...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Rep Power

    Lightbulb Solution

    1. <%
    2. //getting the parameter

    3. String fprice = request.getParameter("price");

    4. //converting parameter to double type

    5. Double x = Double.valueOf(fprice)

    6. // now i want to do some arithmetic

    7. double y = x / 1.18;

    8. %>

    Ok, the error seems to be in line #5 where you are using the Java object Double instead of the Java primitive double. I know you are trying to convert fprice into a double, and the best way to do that is:
    String fprice = "15";
    Double x = Double.valueOf(fprice);
    double x1 = x.parseDouble(fprice);
    double y = x1 / 1.18;
    I hope this works. :-)

    Devin Hendricks

    If you need a part-time telecommuting 16 year old Java developer, please contact me, I am looking for work for 10 hours a week. I also know HTML, JavaScript, CSS, DHTML, and PHP & MySQL; I've used them extensively. Thanks.

IMN logo majestic logo threadwatch logo seochat tools logo