怎么把得到的结果为负值的转换为正值?
这是我页面的代码:
<a href="<%=request.getContextPath()%>/station.do?operate=getAdddensity&jk=0.235&ck=0.214">脱硫率</a>
当jk值小于ck 的时候就会是负值
--------------------------
这是action的代码:
public ActionForward getAdddensity(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession();
NumberFormat format = NumberFormat.getPercentInstance();
format.setMaximumFractionDigits(2);
format.setMinimumFractionDigits(2);
double jk = Double.parseDouble(request.getParameter("jk"));
double ck = Double.parseDouble(request.getParameter("ck"));
String result = format.format((jk - ck) / jk);
// String result = (jk-ck)/jk*100+"%";
//调用计算脱硫率的方法,得到脱硫率
session.setAttribute("result", result);
return mapping.findForward("addDensity");
}
要怎么改呢?
------解决方案--------------------String result = format.format(Math.abs(jk - ck) / jk);
------解决方案--------------------