Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Plz help, problems with arithmetic...  RSS feed

 
Ilja Smoli
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • 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).]
 
James Hobson
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Could u explain the difference between Double and double, plz
Thx..
 
Bosun Bello
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • 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
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • 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).]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!