I'm having problems performing math in JSP. I have a line:

double percentage = (useful / nonuseful) * 100;

which is giving me an error, how do I fix this?

Thanks

Recommended Answers

All 4 Replies

Member Avatar for electron33
<%
        double useful = 12;
        double nonuseful = 24;
        double percentage = ( useful / nonuseful ) * 100;
    %>
    <%= percentage %>

In this example it will be 50.0 in the JSP page.

Okay now I'm getting errors about doubles and integers the values in the database are stored as doubles

Type mismatch: cannot convert from double to int

136: double useful = columns.getDouble("Customer_Useful");
137: double nonuseful = columns.getDouble("Customer_NotUseful");
138: votes = useful + nonuseful;
139: double percentage = (useful / nonuseful) * 100;

Member Avatar for electron33

Can you paste me the whole code. Including variable declaration. Some where in the declaration a variable have been declared int.

Its ok its been solved now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.