Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old December 1st, 2001, 10:43 AM
m0nster m0nster is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2001
Location: Tallinn, .ee
Posts: 28 m0nster User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 27 m 45 sec
Reputation Power: 0
Send a message via ICQ to m0nster
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">

</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...

Reply With Quote
  #2  
Old December 2nd, 2001, 05:02 PM
kenowhere kenowhere is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Posts: 34 kenowhere User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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
sitesuwant@sitesuwant.com
www.sitesuwant.com

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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Plz help, problems with arithmetic...


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway