aspose file tools*
The moose likes Java in General and the fly likes How to Convert an HTML PARAM into a Java Double Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to Convert an HTML PARAM into a Java Double" Watch "How to Convert an HTML PARAM into a Java Double" New topic
Author

How to Convert an HTML PARAM into a Java Double

Jason Foster
Greenhorn

Joined: Feb 13, 2006
Posts: 1
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);
}
}
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

double rate = Double.parseDouble(rateAsString);

Note that this throws NumberFormatException.
[ February 13, 2006: Message edited by: Satou kurinosuke ]

[My Blog]
All roads lead to JavaRanch
Sri Ram
Ranch Hand

Joined: Oct 03, 2005
Posts: 118
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.
 
jQuery in Action, 2nd edition
 
subject: How to Convert an HTML PARAM into a Java Double