cancel
Showing results for 
Search instead for 
Did you mean: 

Divide values returned to the JSP

Former Member
0 Kudos

I am trying to change a jsp page for ISA 4.0

I would like to divide the netValue by the Quantity on the order.jsp page. How do I divide the returned value from item.getNetValue with the value from item.getQuantity?

They code as it stands at the moment:

<% String Z_temp1 = item.getNetValue(); %>

<% String Z_temp2 = item.getQuantity(); %)

<% out.println(Z_temp1 / Z_temp2 ; %> will not work as they are strings.

The jsp will not work when I have Z_temp1 as an int, I think the method getNetValue only returns strings. Is there a method of casting the returned value?

Please help

Thnks

Naidoo

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

You can cast your strings into integer, float, double datatypes. Instead of casting, we can just use the Double class and pass in a string into the constructor to perform the cast.

Here is how you do it.

<%

//passing string into constuctor of Double Class

Double zTemp = new Double(item.getNetValue());

Double zTemp2 = new Double(item.getQuantity());

Double dividedResult = zTemp/ZTemp2;

%>

To output to the screen, you should be using the following jsp tag:

<%= dividedResult %>

You should be looking at the Java API as your first reference:

http://java.sun.com/j2se/1.4.2/docs/api/

Look for the "Double" class on the left hand side of the screen. Be sure to look at the Constructor Summary and methods that are available (if you need to convert double to integer ect).

Hope this helps...

Message was edited by: Brendon Lipchen