jstl if数值比较问题

kkobebryant 2010-10-22 07:57:45

<c:if test="${a.credit==0}">
DR
</c:if>

a.credit的值为 0.000 , 要怎么转化才能比较? 不要 <c:if test="${a.credit*1==0}"> 的类似答案 ,谢
...全文
526 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
blazingfire 2010-10-22
  • 打赏
  • 举报
回复
搞了半天早到一个jstl处理方法,用fmt:parseNumber 装换成数字再比较:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<style type="text/css"></style>
</head>
<body>

<c:set var="credit" value="0.000" />
<c:if test="${credit==0}">
DR1
</c:if>

<fmt:parseNumber value="${credit}" type="number" var="credit2"></fmt:parseNumber>
<c:if test="${credit2==0}">
DR2
</c:if>

</body>
</html>
blazingfire 2010-10-22
  • 打赏
  • 举报
回复
3楼的方法不容易呀。

楼主自己给的方法还简洁多了
magong 2010-10-22
  • 打赏
  • 举报
回复
有一个方案,用起来不是很麻烦,实现嘛,有点麻烦。
定义个自定义标签
类代码:
public class MyFunctions {
public MyFunctions(){}
public static int toInt(double in){
return (int)in;
}
}

TLD文件
	<uri>MyFunctions</uri>
<tlib-version>1.0</tlib-version>
<jsp-version>2.0</jsp-version>
<short-name>MyFunctions</short-name>
<function>
<name>toInt</name>
<function-class>xxx.MyFunctions</function-class>
<function-signature>int toInt(double)</function-signature>
</function>

然后在页面中就可以这样:
<%@ taglib uri="MyFunctions" prefix="myf" %>
<c:if test="${myf:toInt(a.credit) == 0}">
DR
</c:if>

magong 2010-10-22
  • 打赏
  • 举报
回复
还别说,我就觉得你自己给的方案是最好的。
Elim-Zhang 2010-10-22
  • 打赏
  • 举报
回复
把0改成0.000试一下

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧