how to trim leading zeros before displaying the field in jsp?

这一生的挚爱 提交于 2020-01-06 08:32:16

问题


I have data coming into JSP from database. this has teh value like 0000000019 (string). I need to display it as 19. leading zeros needs to trimed out.how would you do it in jsp?

Update

see I have a session variable as :

<c:set var = "tCharge" value="${redata.totalCharge}" /> 

how do you trm all the leading zeros from "tCharge" or ${redata.totalCharge}


回答1:


You can use <fmt:formatNumber value="${redata.totalCharge}"/>




回答2:


Always zeros? Converting it to number should do it.

<%
  String sNum="0000000019";
  int iNum = Integer.parseInt(sNum);
  sNum = Integer.toString(iNum);
%>



回答3:


is the data an integer number? the fastest way is

<%=Integer.parseInt("0000000019")%>

or if it comes from the session...

<%=Integer.parseInt(((YourRedataClass)session.getAttribute("redata")).getTotalCharge())%>



回答4:


fmt:formatNumber didn't work for me. But fmt:parseNumber works:

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:parseNumber value="0000000123456" />


来源:https://stackoverflow.com/questions/4786966/how-to-trim-leading-zeros-before-displaying-the-field-in-jsp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!