• 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

How to Convert an HTML PARAM into a Java Double

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the HTML:

<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>
Applet Test Page
</TITLE>
</HEAD>
<BODY>
<h2 align="center"><span style="font-weight: 400"> <font face="Courier New" size="2">App.html</font></span></h2>
<h2 align="center"><b>Applet Test Page</b></h2>
<p align="center">This page launches a 300 x 200 pixel
applet named:   <font face="Courier New" size="2">App.class</font></p>
<p align="center">
<APPLET CODE=App WIDTH=300 HEIGHT=200>

<PARAM NAME=number VALUE=9>
<PARAM NAME=Date VALUE="5/4/2007">
<PARAM NAME=finChg VALUE=.12>

</APPLET></p>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<blockquote>
<p align="left">NOTES:</p>
<ol style="margin-top: 18">
<li>
<p style="margin-bottom: 18">If the applet doesn't run, make
sure your browser is Java-enabled.</p></li>
<li>
<p style="margin-bottom: 18">Some browsers, such as <i>Internet Explorer</i>, may require "plug-ins".
Other browsers, such as <i>Mozilla Firefox</i>, may not.</p></li>
</ol>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<p align="left"> </p>
</BODY>
</HTML><!-- text below generated by server. PLEASE REMOVE --><!-- Counter/Statistics data collection code --><script language="JavaScript" src="http://hostingprod.com/js_source/geov2.js"></script><script language="javascript">geovisit();</script><noscript><img src="http://visit.webhosting.yahoo.com/visit.gif?us1139632765" alt="setstats" border="0" width="1" height="1"></noscript>
<IMG SRC="http://geo.yahoo.com/serv?s=76001404&t=1139632765" ALT=1 WIDTH=1 HEIGHT=1>


And this is the Java:

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.text.*;
import java.lang.*;

public class App extends Applet {
public void init() {
resize(250, 50);
setLayout(new BorderLayout());
String rateAsString = getParameter("finChg"); // RETRIEVE HTML PARAMETER
double rate = valueOf("getParameter("finChg")"); // CONVERT TO PRIMITIVE FORM ???HOW???
NumberFormat nf = NumberFormat.getPercentInstance();
Label message = new Label("Finance charge: " + nf.format(rate));
message.setAlignment(Label.CENTER);
message.setFont(new Font("SansSerif", Font.BOLD, 18));
add(message, BorderLayout.CENTER);
}
}
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
double rate = Double.parseDouble(rateAsString);

Note that this throws NumberFormatException.
[ February 13, 2006: Message edited by: Satou kurinosuke ]
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
Its simple really.
double rate = (new Double(Double.parseDouble(finChg))).doubleValue()
Convert the String to Double and then convert it back to primitive type.
 
reply
    Bookmark Topic Watch Topic
  • New Topic