该taglib解决了jsp fmt:formatNumber 四舍五入 奇入偶不入的问题
1先写一个tld
1.0 1.2 holyant http://www.holyant.com/jsp NormalRound com.junf.bbd.common.taglibs.HolyantTag value true scale true
2.web.xml 配置
http://www.holyant.com/jsp /WEB-INF/tlds/holyant.tld
3. 创建class HolyantTag
package com.junf.bbd.common.taglibs;import org.apache.taglibs.standard.tag.el.fmt.FormatNumberTag;import javax.servlet.jsp.JspException;import java.math.BigDecimal;public class HolyantTag extends FormatNumberTag { private static final long serialVersionUID = 1L; private int scale; @Override public int doEndTag() throws JspException { BigDecimal v = new BigDecimal(value.toString()); try { pageContext.getOut().print(v.setScale(scale, BigDecimal.ROUND_HALF_UP).toString()); } catch (Exception e) { throw new JspException(e.getMessage()); } return EVAL_PAGE; } public int getScale() { return scale; } public void setScale(int scale) { this.scale = scale; }}
4. jsp中使用
<%@taglib prefix="holyant" uri="http://www.holyant.com/jsp"%>