• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Plz help, problems with arithmetic...

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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">
</form
-----------------------------------------------
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...
[This message has been edited by Ilja Smoli (edited December 02, 2001).]
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
x is a Double not a double, I think you need to replace x with x.doubleValue()
 
Ilja Smoli
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could u explain the difference between Double and double, plz
Thx..
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
double is a primitive. While Double is an object, specifically a wrapper object. If you want to treat a doule primitive as an object (ex: to insert it in a collection) you will wrap it in a Double. OTOH, to get the primitive value of a Double, you will use the doubleValue() method.


------------------
Bosun
SCJP for the Java� 2 Platform
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And since you don't really need a Double in any mathematical operation, you could use the following:
[This message has been edited by Mike Curwen (edited December 02, 2001).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic