PDA

View Full Version : JavaServer question


consultant65
05-29-02, 01:39
I am using JSP 1.0.1 and I need function to convert:

1. String to Double
2. Double to String

Please post your replies ASAP.

gautesmaaland
05-31-02, 05:05
Double to String: String.valueOf(double)

String to double: Double.parseDouble(String s)

consultant65
05-31-02, 23:24
Thanks.
Can you explain with an example.

gautesmaaland
06-01-02, 11:10
Say you have a bean called MyBeanwith with a field f1 ( a double)
In your jsp page:
<jsp:useBean id="bean_instance" scope="session" class="com.package.MyBean" />

Parsing an incoming parameter to a double:

<%
String double_str=request.getParameter("double_val");
double dbl = Double.parseDouble(double_str);
%>

<jsp:setProperty name="bean_instance" property="f1" value="<%=dbl%>" />

The other way round :

<%
String parsed_double=String.valueOf(dbl);
%>